FG
๐ŸŒ Web & Full-StackVercel

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './server.edge' is not defined by "exports"

Freshabout 21 hours ago
Mar 14, 20260 views
Confidence Score94%
94%

Problem

Verify canary release - [X] I verified that the issue exists in the latest Next.js canary release Provide environment information [code block] Which area(s) of Next.js are affected? (leave empty if unsure) _No response_ Link to the code that reproduces this issue sorry i can't upload because my project contains localhost database connections To Reproduce On my own server.js file, every page of my application in development mode gets the same error, while on my own server.js file in localhost in production mode, I get this error on the pages under [slug]! When I run this with my server.js file I get this error. While it then worked on 13.3.1, it's now broken! What am I missing in my server.js file or what should I do? I got this error in the last 13.3.2-canary.7 and it continued in later versions! Normally, I get this error when I refresh the pages under news-media/[slug] and other pages under news-media/[slug] while opening in production mode. I get this error on every page in development mode!"dev": "next dev", "build": "next build", While "start": "next start" was OK, as I mentioned above on my server.js file, after the "next 13.3.1" version, errors started on server.js both in development and production mode! Here's my run npm commands for my own server.js: "httpsDevelopment": "node --max_old_space_size=8192 server/server.js", "httpsProduction": "next build && node server/server.js production", My server.js file looks like this: [code block] De

Error Output

error on the pages under [slug]! When I run this with my server.js file I get this error. While it then worked on 13.3.1, it's now broken!

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix โ€“ Awaiting Verification

Fix ERR_PACKAGE_PATH_NOT_EXPORTED in Next.js Canary Release

Medium Risk

The error [ERR_PACKAGE_PATH_NOT_EXPORTED] indicates that the specified subpath './server.edge' is not defined in the 'exports' field of the package.json for the Next.js package. This often occurs when there are breaking changes in the Next.js version that alter how certain modules are exported, especially in canary releases where experimental features may not be fully stable.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Update server.js to use correct imports

    Ensure that your server.js file is importing the correct modules as per the latest Next.js documentation. The error may stem from using outdated or incorrect import paths.

    javascript
    const { createServer } = require('http');
    const next = require('next');
    
    const dev = process.env.NODE_ENV !== 'production';
    const app = next({ dev });
    const handle = app.getRequestHandler();
    
    app.prepare().then(() => {
      createServer((req, res) => {
        handle(req, res);
      }).listen(3000, (err) => {
        if (err) throw err;
        console.log('> Ready on http://localhost:3000');
      });
    });
  2. 2

    Check package.json for exports

    Verify that your package.json file for Next.js includes the necessary exports for the modules you are trying to use. If you are using a custom server, ensure that you are not referencing any internal paths that are not exported.

    json
    /* Ensure your package.json includes something like this: */
    "exports": {
      "./server.edge": "./path/to/server.edge"
    }
  3. 3

    Reinstall dependencies

    Sometimes, issues arise from corrupted or outdated node modules. Delete your node_modules folder and package-lock.json file, then reinstall your dependencies to ensure you have the latest compatible versions.

    bash
    rm -rf node_modules package-lock.json && npm install
  4. 4

    Test in Development and Production

    Run your application in both development and production modes to ensure that the error has been resolved. Use the commands specified in your package.json to start the server.

    bash
    npm run dev && npm run httpsProduction
  5. 5

    Monitor for further errors

    After making the changes, monitor your application for any new errors or warnings that may arise. This will help ensure that the fix is stable and that no other issues have been introduced.

    none
    Check console logs and network requests in the browser's developer tools.

Validation

Confirm that the application runs without throwing the [ERR_PACKAGE_PATH_NOT_EXPORTED] error in both development and production modes. Additionally, check that all pages, including those under [slug], render correctly without errors.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

nextjsreactssrbuglinear:-nextlocked