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

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: win32
      Arch: x64
      Version: Windows 10 Pro
    Binaries:
      Node: 18.15.0
      npm: N/A
      Yarn: N/A
      pnpm: N/A
    Relevant packages:
      next: 13.3.5-canary.6
      eslint-config-next: 13.3.2
      react: 18.2.0
      react-dom: 18.2.0

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:

Screenshot_20

const { createServer } = require('https')
const { parse } = require('url')
const next = require('next')
const fs = require('fs')
const dev = process.argv[2] !== 'production'
const serverProduct = process.argv[3] === 'server' || undefined

process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
const hostname = 'localhost'
const port = 443
// when using middleware hostname and port must be provided below
const app = next({ dev, hostname, port })
const handle = app.getRequestHandler()
const httpsOptions = {
key: fs.readFileSync(./server/certificates/${serverProduct ? 'cloudflare.key' : 'server.key'}),
cert: fs.readFileSync(./server/certificates/${serverProduct ? 'cloudflare.pem' : 'server.crt'}),
}
app.prepare().then(() => {
createServer(httpsOptions, async (req, res) => {
try {
const parsedUrl = parse(req.url, true)
await handle(req, res, parsedUrl).then(null)
} catch (err) {
console.error('Error occurred handling', req.url, err)
res.statusCode = 500
res.end('internal server error')
}
})
.once('error', (err) => {
console.error(err)
process.exit(1)
})
.listen(port, () => {
console.log(> Ready on https://${hostname})
})
})

Describe the Bug

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!

While in development: dev1 dev2

While in production: prod1 prod2

Expected Behavior

I expect it to run smoothly on my own server.js file, both in development and production mode. I have 2 similar tickets closed. But the problem persists in a similar way!

Which browser are you using? (if relevant)

Chrome 112.0.5615.138

How are you deploying your application? (if relevant)

on my localhost with the command “next build && node server/server.js production”. or “node --max_old_space_size=8192 server/server.js”

NEXT-1413

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 46
  • Comments: 174 (30 by maintainers)

Commits related to this issue

Most upvoted comments

Amplify fix that worked for me

  1. Set environment variable __NEXT_PRIVATE_PREBUNDLED_REACT=next

  2. Add server runtime access to build settings:

build:
    commands:
      - env | grep -e __NEXT_PRIVATE_PREBUNDLED_REACT >> .env.production
      - npm run build

still not working on 13.4.0

Was also having this issue today on vercel on next@13.4.19 and upgrading to 13.5.2 fixed it

I have tested several times and this issue is reproducible on vercel with next version below 13.5.1 (tested with 13.14.18, 13.4.19 and all fail on vercel with the same error, while locally dev/build works fine)

UPD: another solution to this issue is to set the env var VERCEL_CLI_VERSION=vercel@32.2.5 on vercel More info: https://github.com/vercel/vercel/issues/10564

Upgrading next to 13.5.2 fixed it for md

For anyone having problems deploying to vercel, upgrading to 13.5.2 fixed the issue for me.

Hello everyone. Try output: 'standalone', in your next.config.js. it seems working on netlify.

example code:

/** @type {import('next').NextConfig} */
const nextConfig = {
  output: 'standalone',
};

module.exports = nextConfig;

I’m currently on 13.4.2 and I’m still having the same error even though I’m running it locally on my machine.

This is an issue when deployed to netlify with 13.4.1. What’s worse is netlify won’t except then env variable because it starts with _

@karlhorky yeah agreed it’s hard to debug without a repro, but I couldn’t yet put my finger on what trigger this issue. My app is open source but not minimal.

It feels like a problem in the react-dom package export map.

The export map of “react-dom” is like so:

  "exports": {
    ".": "./index.js",
    "./client": "./client.js",
    "./server": {
      "deno": "./server.browser.js",
      "worker": "./server.browser.js",
      "browser": "./server.browser.js",
      "default": "./server.node.js"
    },
    "./server.browser": "./server.browser.js",
    "./server.node": "./server.node.js",
    "./profiling": "./profiling.js",
    "./test-utils": "./test-utils.js",
    "./package.json": "./package.json"
  },

So no “server.edge” indeed. I am using 18.2.0. It doesn’t match what I see in GitHub here: https://github.com/facebook/react/blob/7cd98ef2bcbc10f164f778bade86a4daeb821011/packages/react-dom/package.json

So the latest version of react-dom seems to be not enough.

Edit: the issue seems to disappear with “react-dom” 18.3 canary release indeed (for lost googlers: this is obviously a bad idea ti use react-dom canary version in your app).

I don’t get why “server.edge” is loaded in the first place, that’s probably the underlying issue.

“__NEXT_PRIVATE_PREBUNDLED_REACT=next” is the temporary fix that works

Here are some detailled logs if that can help someone:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './server.edge' is not defined by "exports" in /home/eric-burel/code/devographics/monorepo/node_modules/.pnpm/next@13.4.1_vgii64pd2ccbnbx2v3ro5gbin4/node_modules/react-dom/package.json
    at new NodeError (node:internal/errors:387:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:464:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:748:3)
    at resolveExports (node:internal/modules/cjs/loader:493:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:533:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:942:27)
    at /home/eric-burel/code/devographics/monorepo/node_modules/.pnpm/next@13.4.1_vgii64pd2ccbnbx2v3ro5gbin4/node_modules/next/dist/server/require-hook.js:180:36
    at Function.Module._load (node:internal/modules/cjs/loader:804:27)
    at Module.require (node:internal/modules/cjs/loader:1028:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at /home/eric-burel/code/devographics/monorepo/node_modules/.pnpm/next@13.4.1_vgii64pd2ccbnbx2v3ro5gbin4/node_modules/next/dist/server/app-render/app-render.js:946:37
    at /home/eric-burel/code/devographics/monorepo/node_modules/.pnpm/next@13.4.1_vgii64pd2ccbnbx2v3ro5gbin4/node_modules/next/dist/server/lib/trace/tracer.js:155:62
    at /home/eric-burel/code/devographics/monorepo/node_modules/.pnpm/next@13.4.1_vgii64pd2ccbnbx2v3ro5gbin4/node_modules/next/dist/server/lib/trace/tracer.js:113:36
    at NoopContextManager.with (/home/eric-burel/code/devographics/monorepo/node_modules/.pnpm/next@13.4.1_vgii64pd2ccbnbx2v3ro5gbin4/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)
    at ContextAPI.with (/home/eric-burel/code/devographics/monorepo/node_modules/.pnpm/next@13.4.1_vgii64pd2ccbnbx2v3ro5gbin4/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)
    at NoopTracer.startActiveSpan (/home/eric-burel/code/devographics/monorepo/node_modules/.pnpm/next@13.4.1_vgii64pd2ccbnbx2v3ro5gbin4/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)
    at ProxyTracer.startActiveSpan (/home/eric-burel/code/devographics/monorepo/node_modules/.pnpm/next@13.4.1_vgii64pd2ccbnbx2v3ro5gbin4/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)
    at /home/eric-burel/code/devographics/monorepo/node_modules/.pnpm/next@13.4.1_vgii64pd2ccbnbx2v3ro5gbin4/node_modules/next/dist/server/lib/trace/tracer.js:102:107
    at NoopContextManager.with (/home/eric-burel/code/devographics/monorepo/node_modules/.pnpm/next@13.4.1_vgii64pd2ccbnbx2v3ro5gbin4/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)
    at ContextAPI.with (/home/eric-burel/code/devographics/monorepo/node_modules/.pnpm/next@13.4.1_vgii64pd2ccbnbx2v3ro5gbin4/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)
    at NextTracerImpl.trace (/home/eric-burel/code/devographics/monorepo/node_modules/.pnpm/next@13.4.1_vgii64pd2ccbnbx2v3ro5gbin4/node_modules/next/dist/server/lib/trace/tracer.js:102:32)
    at /home/eric-burel/code/devographics/monorepo/node_modules/.pnpm/next@13.4.1_vgii64pd2ccbnbx2v3ro5gbin4/node_modules/next/dist/server/lib/trace/tracer.js:155:31
    at wrappedRender (/home/eric-burel/code/devographics/monorepo/node_modules/.pnpm/next@13.4.1_vgii64pd2ccbnbx2v3ro5gbin4/node_modules/next/dist/server/app-render/app-render.js:997:62) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

The error seems to be still present in 13.4.3 when creating a minimal app with create-next-app that is rendering a simple server-component that uses fetch(..., { cache: 'no-store' })

Is anyone having this issue directly on Vercel? I’m using Next 13.4.19 and the next.config.js file hasn’t changed since things were working flawlessly. The only difference I can gather between the builds that were working and the last 5-6 attempts to build is the vercel CLI version being used on Vercel. The builds were working flawlessly with Vercel CLI 32.2.5 to returning this error on every page when building with Vercel CLI 32.3.0. Apart from this change that, as far as I know, is a change made by Vercel nothing in the app has changed apart from basic tsx content. I should note though, that there are other file types in the repo but they’re not being accessed by any part of the app.

I’m using the App router entirely, so there is no page directory in the app at all. I’ll keep working on it and post my success if I find one, but any help is greatly appreciated.

I also have this issue with this setup:

  • Next.js: 13.4.10
  • Node: 16
  • Deploy with AWS Amplify
  • No custom server
  • Not happened in local
  • App Router
  • Dynamic route

This fix worked for my case 💯 🥇

Amplify fix that worked for me

  1. Set environment variable __NEXT_PRIVATE_PREBUNDLED_REACT=next
  2. Add server runtime access to build settings:
build:
    commands:
      - env | grep -e __NEXT_PRIVATE_PREBUNDLED_REACT >> .env.production
      - npm run build

Ok I had some help w/ the issue, the problem was this: I’m using a custom request handler (not a custom server per se) and needed to set process.env__NEXT_PRIVATE_PREBUNDLED_REACT = 'next'; @Anerco try that.

Upon further investigation, seems like this PR #48840 changed ReactDOMServer import from server.browser to server.edge here. This should not cause import resolving issues as it’s importing directly from the “compiled” version next/dist/compiled/react-dom/server.edge

PR #48896 changed this same import from next/dist/compiled/react-dom/server.edge to react-dom/server.edge which could cause this resolving to the wrong package.

PR #49202 removed this import altogether and moved it in-line

Seems like the latest change is not released yet. It might resolve this issue. Maybe pinging @shuding here as the last two changes are made by you and might be related to this issue?

EDIT: did not scroll far enough 😅 #49202 is released in 13.4.0, so it’s still not fixing this issue, as we are experiencing this with 13.4.1 at least

We’re seeing this issue today on our vercel deployment. We’re not using a custom server and it isn’t happening on our local.

We’re using next 13.4.1 with turborepo and pnpm on node 18.

  • info Loaded env from /var/task/apps/web/.env.production Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath ‘./server.edge’ is not defined by “exports” in /var/task/node_modules/.pnpm/next@13.4.1_@babel+core@7.21.3_react-dom@18.2.0_react@18.2.0/node_modules/react-dom/package.json at new NodeError (node:internal/errors:399:5) at exportsNotFound (node:internal/modules/esm/resolve:366:10) at packageExportsResolve (node:internal/modules/esm/resolve:702:9) at resolveExports (node:internal/modules/cjs/loader:565:36) at Module._findPath (node:internal/modules/cjs/loader:634:31) at Module.resolveFilename (node:internal/modules/cjs/loader:1061:27) at /var/task/node_modules/.pnpm/next@13.4.1@babel+core@7.21.3_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/require-hook.js:180:36 at Module._load (node:internal/modules/cjs/loader:920:27) at Module.require (node:internal/modules/cjs/loader:1141:19) at require (node:internal/modules/cjs/helpers:110:18) { code: ‘ERR_PACKAGE_PATH_NOT_EXPORTED’, page: ‘’ } RequestId: xxx Error: Runtime exited with error: exit status 1 Runtime.ExitError

Same issue deploying to Azure static web app. Lastest working next npm version is 13.2.4

Wanted to backup @A7med3bdulBaset, hit the same issue, was running “next”: “latest” and it was failing. Changed to 13.5.2 and all this issue went away on Vercel.

UPDATE: Wanted to say did not have to do anything else, no env vars, no import next, etc as seen elsewhere to get the server action working (from a form in my case).

I solve this only by change node v16 to v18.

All of a sudden, now I have this problem… I just upgraded to the lastest release…

Just confirming, upgrading Next did resolve the issue. Caused some minor issues in the process but that’s really got nothing to do with Next, just version mismatches. Thanks to @ubirajaramneto and @VladSez for sharing their findings.

I love how next developers ignore everyone and everything

Same error here.

I am seeing this issue when building Next v13.4.2 with output: standalone (so no custom server.js). Then when I run node .next/standalone/server.js I get this error. Just FYI in case this information helps reproduce this, as I haven’t seen anyone mention the standalone build yet.

Full error here:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './server.edge' is not defined by "exports" in [project]/.next/standalone/node_modules/.pnpm/next@13.4.2_@babel+core@7.21.8_react-dom@18.2.0_react@18.2.0/node_modules/react-dom/package.json
    at new NodeError (node:internal/errors:393:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:358:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:668:3)
    at resolveExports (node:internal/modules/cjs/loader:529:36)
    at Module._findPath (node:internal/modules/cjs/loader:569:31)
    at Module._resolveFilename (node:internal/modules/cjs/loader:981:27)
    at [project]/.next/standalone/node_modules/.pnpm/next@13.4.2_@babel+core@7.21.8_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/require-hook.js:180:36
    at Module._load (node:internal/modules/cjs/loader:841:27)
    at Module.require (node:internal/modules/cjs/loader:1061:19)
    at require (node:internal/modules/cjs/helpers:103:18) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

The issue indeed seems to be with the react-dom/server.edge import in src/server/require-hook.js. What is happening in our codebase is that this line specifically is getting called as __NEXT_PRIVATE_PREBUNDLED_REACT is getting value next. This import was added in PR #48840 2 weeks ago, so the timing would match with this 🤔

react/dom has last released in June 2022 with 18.2.0, and server.edge export was added Feb 7 this year, so it’s not present in the published version.

Seems like Next has a compiled version of react-dom defined here which contains the server.edge export present (it’s using 18.3.0 canary)

Not sure exactly what is happening here, but the problem seems to be that at least in our codebase, the react-dom/server.edge resolves to react-dom package installed in our own project /frontend/node_modules/react-dom/package.json which is obviously the wrong version for this import. Maybe the compiled version and installed version are getting confused somehow? The exact exception is happening on this line.

EDIT: seems like __NEXT_PRIVATE_PREBUNDLED_REACT is getting many different values, both undefined and next. When importing react-dom/server.edge, the value actually seems to be undefined which would explain the import resolving to our installed react-dom which is obviously incorrect, as the above overrideReact is not getting called. So the issue might be that react-dom/server.edge is being used somewhere while react-dom is not getting overridden by the Next compiled version

This issue

TypeError: Cannot create property 'propTypes' on number 'Infinity'

on next 13.5.2 was caused by react-bootstrap-icons - I could see that with npm run dev instead of build

TypeError: Cannot create property 'propTypes' on number 'Infinity'
    at eval (webpack-internal:///(rsc)/./node_modules/react-bootstrap-icons/build/index.js:38058:20)
    at (rsc)/./node_modules/react-bootstrap-icons/build/index.js (/home/jdb/projects/opensanctions/operations/site/.next/server/vendor-chunks/react-bootstrap-icons.js:20:1)

Adding react-bootstrap-icons to nextConfig.experimental.serverComponentsExternalPackages fixed it for me.

Yes I used vercel for deployment now it’s working fine…

On Fri, Aug 18, 2023, 4:58 PM Oliver K @.***> wrote:

The - env | grep -e __NEXT_PRIVATE_PREBUNDLED_REACT >> .env.production Triggered another error.

2023-08-15T20:59:04.824Z [INFO]: # Executing command: env | grep -e __NEXT_PRIVATE_PREBUNDLED_REACT >> .env.production 2023-08-15T20:59:04.826Z [ERROR]: !!! Build failed 2023-08-15T20:59:04.826Z [INFO]: Please check the supported SSR features to find if your build failure is related to an unsupported feature: https://docs.aws.amazon.com/amplify/latest/userguide/ssr-Amplify-support.html#supported-unsupported-features. You may also find this troubleshooting guide useful: https://docs.aws.amazon.com/amplify/latest/userguide/troubleshooting-ssr-deployment.html

I checked the unsuported features the project is using none. (it compiles fine without the __NEXT_PRIVATE_PREBUNDLED_REACT , but gets the same error 500 as said above)

have you had any progress here?

I’m having the same issues. I’ve downgrading next to 13.4.9 and that fixed netlify deployment but same issues on AWS. Ive tried with and without the env variable and the build function. As you did, the build function seems to throw an error. Without it the site builds but server 500 page.

— Reply to this email directly, view it on GitHub https://github.com/vercel/next.js/issues/49169#issuecomment-1683780497, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARTDAM4JTRAT23YXTKZFDVTXV5GWHANCNFSM6AAAAAAXU2XDQ4 . You are receiving this because you commented.Message ID: <vercel/next. @.***>

I managed to get the deploy working by using the prebuild.js script but also removing the env variable __NEXT_PRIVATE_PREBUNDLED_REACT that I previously added via Netlify CLI.

However, when I go to the deploy preview I see the error: image

It looks like react-dom doesn’t have server.edge included in its package.json exports. It’s currently on their main branch, but not in their npm package.

Edit: I’ve just seen someone has already mentioned this earlier on. Unfortunately __NEXT_PRIVATE_PREBUNDLED_REACT cannot be set on Netlify, so it’s still an issue.

This issue lingers it seems. If anyone here is using AWS Amplify, __NEXT_PRIVATE_PREBUNDLED_REACT hack/fix works as long as you ensure the server-side runtime has access to it.

I am also facing this issue when using server actions. Although the error is thrown, everything seems to be working correctly. Can this issue be reopened?

Getting this error with Next 13.4.3 when calling nextApiResponse.revalidate('...')

Error goes away when adding __NEXT_PRIVATE_PREBUNDLED_REACT=next to .env

@esauri I had a similar issue with next 13.4.1, turborepo, pnpm and node 18.

In my case, client-side navigation to a dynamic (app router) page would work, but performing a full reload would give the same error.

Triggering a Redeploy with the Use existing Build Cache option unchecked seemed to resolve it for me.

Potentially an issue with the pnpm store cached by turborepo? I’m not sure - let me know if it works for you.

@shuding Was this suppose to be fixed in 13.3.5-canary.8? I’m still seeing the same error 😕

There was an incident with the latest Vercel CLI release that affected some customer deployments.

Please follow our status page for the latest updates: https://www.vercel-status.com/incidents/dg7l3pz92c19

I hope the team explains why this problem has occurred to so many since yesterday and today. Is it an internal problem in Vercel? I didn’t update any packages and it occurred. Moreover, Re-building old successful build cases the error!

Why updating to next 13.5.2 fixes it?

UPD: another solution to this issue (besides updating to latest next version) is to set the env var VERCEL_CLI_VERSION=vercel@32.2.5 on vercel More info: https://github.com/vercel/vercel/issues/10564

updating to next => 13.5.2 did the trick

If this is happening in vercel, see the following issue. vercel/vercel#10564

Ran into the above like everyone else today. Upgrading from 13.4.9 to 13.5.2 worked, but caused some cascading problems in other areas. In my particular case, I needed to make changes to some of my open-graph routes. Replacing vercel/og with next/server and making some minor changes were also necessary.

Same here. App was deploying normally until some hours ago, then suddenly this error have shown. The app is deploying as normal, but the home page mysite.com/ is not being rendered. I get a “500 Internal Server Error.” and in the logs I can see this ERR_PACKAGE_PATH_NOT_EXPORTED Package subpath './server.edge' is not defined by "exports" in /var/task/node_modules/react-dom/package.json.

My site has only this home page, a terms of service and a privacy policy pages. ToS and PP are working just fine. The error is only on home. api/ endpoints are working fine, including next-auth ones.

I tried to remove node_modules and install Next js 13.5.2 (was on 13.4.19), but it didn’t make it to me. Still getting the same error. Everything is working fine in dev environment.

I didn’t any change to my home page in the deploy I see this error at the first time.

Edit: I’ve forget to mention but even redeploying old commits is not working.

Hi Folks, Here is a little background on what is causing the reported issue in OPs post.

Next has two routers, Pages Router and App Router.

For Pages Router whatever version of React you choose to install is what is used (it’s a peer dep). The current minimum version is 18.2 which is also the latest React stable.

For App Router regardless of what version of React you have installed Next always uses a vendored version pinned to the latest tested React canary release. If you are using Alpha features like server actions we instead use a version pinned to the latest tested React experimental release.

When executing next’s code or user code we have a hook in place for node’s module resolver that makes a decision about which version of react to load for the give request. To make this determination an environment variable is read (__NEXT_PRIVATE_PREBUNDLED_REACT). This is why under the hood when you use next it should be creating more than one process; one for Pages and one for App Router. Each process can have different environment variables and thus the resolution of React imports can be different in different scopes

What seems to be happening in OP’s original issue is there is a module resolution for a Canary channel react API (it’s looking for react-dom/server.edge which does not exist in React 18.2 but does exist in React Canary. This suggests to me that the process handling an App Router request is not correctly running with the right environment variables.

Now if you are using the const next = require('next') as OPs custom server appears to be doing all of this should be handled entirely internal to next and there should be no need for patching environment variables. If you are doing something more invasive then it’s possible controlling your processes and making sure the environment is set up correctly may be necessary.

This issue is fairly old and a lot of updates have landed in newer releases. What I would like to ask of folks in this thread is to try to use the latest release of next and if you still have this issue please open a new one providing details about the failure

  1. the specific error when responding to an App Router route in dev and in prod (if applicable)
  2. the specific error when (if) responding to a Pages route in dev and in prod (if applicable)
  3. the host you experience this issue on
  4. A link to a reproducing repo if possible, otherwise the custom server code
  5. the version of next you tested it on (should be latest stable)
  6. Confirm that you are not manually setting __NEXT_PRIVATE_PREBUNDLED_REACT environment variable (check your .env files)

Link your new issue to this issue so we can more easily find it. If you see an issue that is the same as yours (same error, on same host in same environment, please feel free to comment there. If there are differences such as different error, or you are running on a different host please open a separate issue.

Same here. I migrated a page from pages to app directory, it loads correctly but not when hitting a rewrite rule. Version 13.4.8

Rewrite rule (working in pages not in app directory) source: /guides/:slug dest: /blog/article/:slug

/blog/article/:slug works /guides/:slug not working (Error[ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath ‘./server.edge’

@shuding Given that this ticket still gets several “this is still happening with {recent version of Nextjs}” messages every week, can this be re-opened? Or is this problem just considered to have been fixed/working as intended?

A workaround for everyone on Vercel or Netlify 🎉 (who can’t set the environment variable because of the underscores):

https://answers.netlify.com/t/server-edge-not-defined-error-on-nextjs-ssr-functions-cause-site-to-return-500-errors/91793/31

It requires you to patch the require-hook of nextjs, which checks the environment varable. Which can looks something like this:

import path from 'node:path';
import fs from 'fs';

const baseDir = process.cwd();

const patchNextRequireHook = async () => {
  const file = path.join(
    baseDir,
    'node_modules',
    'next',
    'dist',
    'server',
    'require-hook.js'
  );

  const content = await fs.promises.readFile(file, 'utf-8');
  await fs.promises.writeFile(
    file,
    content.replace(
      'if (process.env.__NEXT_PRIVATE_PREBUNDLED_REACT) {',
      'if (true) {'
    )
  );
};

patchNextRequireHook();

Run it in your prebuild npm script or in the pipeline before building your application.

same here when starting a standalone output

Just faced the same issue, it only appears when I deploy to vercel, building locally works fine!

More context, not sure if this helps:

I think the previous problem was caused by the newer (experimental or canary) versions of react and react-dom being loaded in environments where they shouldn’t be. So the Next.js require hook should not be trying to load ./server.edge in the first place - something is misconfigured for the environment in which that particular code is running.

Regarding the reproduction: maybe even a non-minimal repro would be helpful, if you can link it.

I can confirm next@13.3.5-canary.8 (first version including PR #49168) is working with custom servers 🎉 Thanks @shuding !!

CodeSandbox: https://codesandbox.io/p/sandbox/quirky-bell-o5tl8l?file=%2Fserver.mjs

Screenshot 2023-05-04 at 11 42 39

UPD: another solution to this issue (besides updating to latest next version) is to set the env var VERCEL_CLI_VERSION=vercel@32.2.5 on vercel More info: vercel/vercel#10564

This did the trick to me. Thanks!

Had the same error happen today, same Next version between deploys (13.4.19), just a minor update that added some POST functions to route handlers that only handled GET.

Updating to 13.5.2 worked.

Confirming , upgrading Nextjs version solved the problem!

Having the same issue when deploying an app on Azure Static Web App. Last working version for me is next-13.4.12 . When upgrading to 13.4.13 or later our middleware which matches locale based on path used with next-intl is not working anymore.

Having the same issue with NextJS latest version (13.4.19) when deploying on Netlify.

Screenshot 2023-08-25 at 16 22 51

I got the same error, the only way to fix it is by downgrading Next.js version to 13.3.4

Amplify fix that worked for me

  1. Set environment variable __NEXT_PRIVATE_PREBUNDLED_REACT=next
  2. Add server runtime access to build settings:
build:
    commands:
      - env | grep -e __NEXT_PRIVATE_PREBUNDLED_REACT >> .env.production
      - npm run build

Worked for me on amplify

We’re facing this issue on 13.4.13 any updates? Hacking this flag does not work ->

__NEXT_PRIVATE_PREBUNDLED_REACT

Screenshot 2023-07-27 at 2 27 04 PM

Fix reposted from Netlify forum that worked for me.

I was deploying a Next.js app on AWS Lambda with sladg/nextjs-lambda.

Create prebuild.js file in the root of your project. This is the code you want:

console.log("********* PREBUILDING *********");
const path = require("node:path");
const fs = require("fs");
const baseDir = process.cwd();

const prebuildScripts = async () => {
  const file = path.join(
    baseDir,
    "/node_modules",
    "next/dist/server/require-hook.js"
  );

  const content = await fs.promises.readFile(file, "utf-8");
  await fs.promises.writeFile(
    file,
    content.replace(
      "if (process.env.__NEXT_PRIVATE_PREBUNDLED_REACT) {",
      "if (true) {"
    )
  );
};

prebuildScripts();

Update package.json to include a prebuild step:

  "scripts": {
    "dev": "next dev",
    "prebuild": "node prebuild.js",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },

For anybody else that this helps:

I was on 13.4.2 and had a basePath configured in next.config.js, and hitting a URL locally without the base path was causing it to throw this error. For example, with a basePath set to /foo, I got the error when hitting /bar.

After upgrading to 13.4.10, I get a 404 as expected instead.

I’m getting this error when setting i18n in next.config.js (standalone build)

I am having the same issue in AWS Amplify.

Same here @mryechkin

I have

“next”: “13.4.7”, “react”: “18.2.0”,

I’m having same issue but only in production (own vps). In dev mode, I get the above-mentioned Multiple rendering error. I cant make a repro as I dont even know which part of the code is throwing this error

I am setting this issue after setting a basePath inside next.config.js

In our case enabling the server actions led to the problem described.

@StevenLangbroek, thanks for sharing the fix of downgrading to 13.4.1! Also ran into this and that immediately solved it for us 🙏

Reporting that we’re seeing this issue as well on 13.4.4 as well as 13.4.5-canary2, but only when deployed, not locally. Downgrading to 13.4.1 fixed this issue for us for now.

Of note here is that Vercel doesn’t allow Environment Variables that start with __, so I can’t apply the proposed fix on their own platform 🤓 (it’s all good, we’re not blocked on it, thought it was worth remarking in case others are running into this as well).

This is what happens in netlify ISR functions when I go to a 404 page

May 21, 01:06:21 PM: 5a686a54 ERROR  Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './server.edge' is not defined by "exports" in /var/task/node_modules/react-dom/package.json
    at new NodeError (node:internal/errors:399:5)
    at exportsNotFound (node:internal/modules/esm/resolve:366:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:702:9)
    at resolveExports (node:internal/modules/cjs/loader:565:36)
    at Module._findPath (node:internal/modules/cjs/loader:634:31)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1061:27)
    at /var/task/node_modules/next/dist/server/require-hook.js:180:36
    at Module._load (node:internal/modules/cjs/loader:920:27)
    at Module.require (node:internal/modules/cjs/loader:1141:19)
    at require (node:internal/modules/cjs/helpers:110:18) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

fix has been rolled

…to where? I’m using 13.4.3 (on Netlify) and it would appear that release was 13 hours ago.

Hi, if you were experiencing this on a deployment please try re-deploying now as a fix has been rolled!

Is there a fix for this? Netlify isn’t allowing env variables with a underscore which means __NEXT_PRIVATE_PREBUNDLEDREACT=next isn’t working.

One can add this variable via netlify CLI:

netlify env:set __NEXT_PRIVATE_PREBUNDLED_REACT next

However the deploy on Netlify fails at initialization phase because:

3:13:45 PM: Failing build: Failed to build site
3:13:45 PM: Failed during stage 'building site': Environment variable key '__NEXT_PRIVATE_PREBUNDLED_REACT' must start with a letter

Tracking along with this from Netlify team.

Hi, this has been updated in v13.4.3, please update and give it a try!

After I upgraded to 13.4.3 I had the issue…I had to downgrade to 13.4.2.

Is there a fix for this? Netlify isn’t allowing env variables with a underscore which means __NEXT_PRIVATE_PREBUNDLEDREACT=next isn’t working.

Seems like PR #48896 did some changes to server.edge importing which could be the cause of this issue: https://github.com/vercel/next.js/pull/48896/files#diff-a3e2e024db1faa1b501e0dd6040eaaf0d931cb9878ae0fb0f4c3658daa982768R18

EDIT: these changes were released in NextJS 13.4.0: https://github.com/vercel/next.js/releases/tag/v13.4.0 , if this issue was happening even before this, might be something else.

I am also getting this exact issue when deploying on Netlify. All was fine until version 13.3.1, but then I upgraded to the latest version and it just crash with this error:

May 12, 11:14:39 AM: 2e6a81a9 ERROR  Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './server.edge' is not defined by "exports" in /var/task/node_modules/react-dom/package.json
    at new NodeError (node:internal/errors:387:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:365:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:649:3)
    at resolveExports (node:internal/modules/cjs/loader:554:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:594:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1012:27)
    at /var/task/node_modules/next/dist/server/require-hook.js:180:36
    at Function.Module._load (node:internal/modules/cjs/loader:871:27)
    at Module.require (node:internal/modules/cjs/loader:1098:19)
    at require (node:internal/modules/cjs/helpers:108:18) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

For some reason it seems to work fine when running netlify dev on my local

Same issue here, not using pnpm or turborepo.

My site got hit by a bit of traffic and it just self exploded by throwing the same Package subpath ‘./server.edge’ error making it go offline.

Not using a custom server either, not sure what is going wrong here.

Here’s the code: https://github.com/Devographics/Monorepo/tree/7a1114660a3a82d26b252fe34a795a475dbb99d0/surveyform You won’t be able to run the app easily but the issue seems to appear when I hit the endpoint in “/pages/api/account/anonymous-login/login”. But maybe it’s not this one. Anyway the home page do open, the issue appears during an API call.

I don’t have instrumentationHook explicitely enabled as far as I can tell. But yeah the logs are pointing there indeed.

It looks like in your stack trace that you have OpenTeletry enabled (maybe via experimental.instrumentationHook = true;?)

Could this be a common denominator for some other people in the thread too?

@eric-burel @PassTheMayo and others, I think what’s missing here is a reproduction of the bug as mentioned above.

Want to try creating one?

Same issue during dev and build, I don’t use turborepo but pnpm, so the common denominator seems to be pnpm

@shuding I think this is not fully solved by the PR, I am using 13.4.0

I’m not using pnpm or Turbo and I’m receiving this error in my production environment using Next 13.4.0 and npm 8.19.3.

Sure, just made the sandbox linked above public - I keep forgetting that CodeSandbox is now private by default.

same for me.