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:
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:
While in production:
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”
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 46
- Comments: 174 (30 by maintainers)
Commits related to this issue
- Fix React channel env missing in custom server (#49168) Fixes #48948 ([repro](https://github.com/vercel/next.js/issues/48948#issuecomment-1533542001)). When running inside a custom server with app ... — committed to vercel/next.js by shuding a year ago
- [next] Update handling for react prebundled flag (#9974) This ensures we properly set the prebundled react flag conditionally for app and pages ensuring they are kept separate when bundling. x-re... — committed to vercel/vercel by ijjk a year ago
- Remove custom handling for prebundled react env (#49954) This removes the previous handling for the prebundled react env we were setting in favor of https://github.com/vercel/vercel/pull/9974 We ... — committed to vercel/next.js by ijjk a year ago
- [next] Ensure app functions are detected/separated properly (#9989) Follow-up to https://github.com/vercel/vercel/pull/9974 this uses the `lambdaAppPaths` as the source of truth instead of the manife... — committed to vercel/vercel by ijjk a year ago
- fix(front): downgrade to next 13.4.1 to fix export error https://github.com/vercel/next.js/issues/49169 — committed to dgrebb/dgrebb.com by dgrebb a year ago
- fix: Downgrade next to 13.4.1 to resolve Netlify issue Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath ./server.edge is not defined by "exports" ref: https://github.com/vercel/next.js/issues/4... — committed to dimkl/aws-clerk-nextjs by deleted user a year ago
- Remove custom handling for prebundled react env (#49954) This removes the previous handling for the prebundled react env we were setting in favor of https://github.com/vercel/vercel/pull/9974 We ... — committed to hydRAnger/next.js by ijjk a year ago
- https://github.com/vercel/next.js/issues/49169 — committed to manumura/nextjs-auth-rbac-starter by manumura a year ago
- fix: Attempt solving build issue https://github.com/vercel/next.js/issues/49169 — committed to Loddon-Social-Enterprise/website by benhodgson87 10 months ago
- fix(package.json,-pnpm-lock.yaml): fix error[ERR_PACKAGE_PATH_NOT_EXPORTED] when deploying to Vercel https://github.com/vercel/next.js/issues/49169 BREAKING CHANGE: nextjs version upgrading — committed to forkidd214/botw-hyrule-compendium by forkidd214 9 months ago
- fix: upgrade next version in recipe to ensure vercel builds pass https://github.com/vercel/next.js/issues/49169\#issuecomment-1730544814 — committed to measuredco/puck by chrisvxd 9 months ago
- fix: upgrade next version in recipe to ensure vercel builds pass https://github.com/vercel/next.js/issues/49169\#issuecomment-1730544814 — committed to measuredco/puck by chrisvxd 9 months ago
Amplify fix that worked for me
Set environment variable
__NEXT_PRIVATE_PREBUNDLED_REACT=next
Add server runtime access to build settings:
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/10564Upgrading 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 yournext.config.js
. it seems working on netlify.example code:
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:
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:
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 usesfetch(..., { 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:
This fix worked for my case 💯 🥇
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 fromserver.browser
toserver.edge
here. This should not cause import resolving issues as it’s importing directly from the “compiled” versionnext/dist/compiled/react-dom/server.edge
PR #48896 changed this same import from
next/dist/compiled/react-dom/server.edge
toreact-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.
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 runnode .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:
The issue indeed seems to be with the
react-dom/server.edge
import insrc/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 valuenext
. 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 with18.2.0
, andserver.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 theserver.edge
export present (it’s using18.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 toreact-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, bothundefined
andnext
. When importingreact-dom/server.edge
, the value actually seems to beundefined
which would explain the import resolving to our installedreact-dom
which is obviously incorrect, as the aboveoverrideReact
is not getting called. So the issue might be thatreact-dom/server.edge
is being used somewhere whilereact-dom
is not getting overridden by the Next compiled versionThis issue
on next 13.5.2 was caused by react-bootstrap-icons - I could see that with
npm run dev
instead ofbuild
Adding
react-bootstrap-icons
tonextConfig.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:
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:
It looks like
react-dom
doesn’t haveserver.edge
included in itspackage.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?
same
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/10564updating to
next => 13.5.2
did the trickIf 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
withnext/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 thisERR_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, includingnext-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 scopesWhat 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
__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 appdirectory
, it loads correctly but not when hitting a rewrite rule. Version13.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: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
andreact-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
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.
I got the same error, the only way to fix it is by downgrading Next.js version to
13.3.4
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
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:Update package.json to include a prebuild step:
For anybody else that this helps:
I was on 13.4.2 and had a
basePath
configured innext.config.js
, and hitting a URL locally without the base path was causing it to throw this error. For example, with abasePath
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
innext.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 errorI 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 as13.4.5-canary2
, but only when deployed, not locally. Downgrading to13.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
…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!
One can add this variable via netlify CLI:
However the deploy on Netlify fails at initialization phase because:
Tracking along with this from Netlify team.
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-a3e2e024db1faa1b501e0dd6040eaaf0d931cb9878ae0fb0f4c3658daa982768R18EDIT: 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:
For some reason it seems to work fine when running
netlify dev
on my localSame 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?
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.