Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task done
dincerpece opened this issue May 3, 2023 · 174 comments · Fixed by #49168 or #49954
Closed
1 task done
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. locked

Comments

@dincerpece
Copy link

dincerpece commented May 3, 2023

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

@dincerpece dincerpece added the bug Issue was opened via the bug report template. label May 3, 2023
@Anerco
Copy link

Anerco commented May 3, 2023

same for me.

shuding added a commit that referenced this issue May 3, 2023
Fixes #48948
([repro](#48948 (comment))).
When running inside a custom server with app dir, we should always opt
into the prebundled React with correct channels.

Thanks @karlhorky for help testing it!

Fixes #49169 too.

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
@khuezy
Copy link
Contributor

khuezy commented May 4, 2023

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

@karlhorky
Copy link
Contributor

karlhorky commented May 4, 2023

I can confirm [email protected] (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

@karlhorky
Copy link
Contributor

karlhorky commented May 4, 2023

Was this suppose to be fixed in 13.3.5-canary.8? I'm still seeing the same error :/

@khuezy maybe you can try creating a reproduction of the error on CodeSandbox? (I think currently, StackBlitz doesn't work because of problems with the binary - at least it was broken yesterday) If you're still getting the error and you're not using a custom server, it is probably some other feature you're using...?

@khuezy
Copy link
Contributor

khuezy commented May 4, 2023

@karlhorky will do. Do you have your codesandbox I can fork? It looks like it's been removed :(

@karlhorky
Copy link
Contributor

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

@Anerco
Copy link

Anerco commented May 4, 2023

still not working on 13.4.0

@khuezy
Copy link
Contributor

khuezy commented May 4, 2023

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.

@nathan2slime
Copy link

Same problem here in version 13.4.0

@Anerco
Copy link

Anerco commented May 5, 2023

next

@khuezy changing the env works (after adding serverActions: true in next.config)

im not sure about the consequences though

@tholder
Copy link

tholder commented May 6, 2023

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 _

@Michaelkire
Copy link

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

@imranbarbhuiya
Copy link
Contributor

imranbarbhuiya commented May 8, 2023

I'm having the same issue on latest version. It happens in both dev (windows) and in production (ubuntu). I'm not using any custom server.

I'm using turborepo with yarn v3. But I don't use turborepo in dev and also I used yarn to build in production and still same issue

@esauri
Copy link

esauri commented May 8, 2023

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[email protected][email protected][email protected]/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/[email protected]
    @babel[email protected][email protected][email protected]/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

@HJGreen
Copy link

HJGreen commented May 9, 2023

@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.

@esauri
Copy link

esauri commented May 9, 2023

@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.

Yes it was resolved a few hours later. I assume it was related to this issue yesterday https://www.vercel-status.com/incidents/mj596gzq35xw.

@eric-burel
Copy link
Contributor

eric-burel commented May 10, 2023

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

@PassTheMayo
Copy link

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.

@karlhorky
Copy link
Contributor

karlhorky commented May 10, 2023

@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?

@eric-burel
Copy link
Contributor

eric-burel commented May 10, 2023

@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/[email protected]_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/[email protected]_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/[email protected]_vgii64pd2ccbnbx2v3ro5gbin4/node_modules/next/dist/server/app-render/app-render.js:946:37
    at /home/eric-burel/code/devographics/monorepo/node_modules/.pnpm/[email protected]_vgii64pd2ccbnbx2v3ro5gbin4/node_modules/next/dist/server/lib/trace/tracer.js:155:62
    at /home/eric-burel/code/devographics/monorepo/node_modules/.pnpm/[email protected]_vgii64pd2ccbnbx2v3ro5gbin4/node_modules/next/dist/server/lib/trace/tracer.js:113:36
    at NoopContextManager.with (/home/eric-burel/code/devographics/monorepo/node_modules/.pnpm/[email protected]_vgii64pd2ccbnbx2v3ro5gbin4/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)
    at ContextAPI.with (/home/eric-burel/code/devographics/monorepo/node_modules/.pnpm/[email protected]_vgii64pd2ccbnbx2v3ro5gbin4/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)
    at NoopTracer.startActiveSpan (/home/eric-burel/code/devographics/monorepo/node_modules/.pnpm/[email protected]_vgii64pd2ccbnbx2v3ro5gbin4/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)
    at ProxyTracer.startActiveSpan (/home/eric-burel/code/devographics/monorepo/node_modules/.pnpm/[email protected]_vgii64pd2ccbnbx2v3ro5gbin4/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)
    at /home/eric-burel/code/devographics/monorepo/node_modules/.pnpm/[email protected]_vgii64pd2ccbnbx2v3ro5gbin4/node_modules/next/dist/server/lib/trace/tracer.js:102:107
    at NoopContextManager.with (/home/eric-burel/code/devographics/monorepo/node_modules/.pnpm/[email protected]_vgii64pd2ccbnbx2v3ro5gbin4/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)
    at ContextAPI.with (/home/eric-burel/code/devographics/monorepo/node_modules/.pnpm/[email protected]_vgii64pd2ccbnbx2v3ro5gbin4/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)
    at NextTracerImpl.trace (/home/eric-burel/code/devographics/monorepo/node_modules/.pnpm/[email protected]_vgii64pd2ccbnbx2v3ro5gbin4/node_modules/next/dist/server/lib/trace/tracer.js:102:32)
    at /home/eric-burel/code/devographics/monorepo/node_modules/.pnpm/[email protected]_vgii64pd2ccbnbx2v3ro5gbin4/node_modules/next/dist/server/lib/trace/tracer.js:155:31
    at wrappedRender (/home/eric-burel/code/devographics/monorepo/node_modules/.pnpm/[email protected]_vgii64pd2ccbnbx2v3ro5gbin4/node_modules/next/dist/server/app-render/app-render.js:997:62) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

@karlhorky
Copy link
Contributor

karlhorky commented May 10, 2023

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.

@karlhorky
Copy link
Contributor

karlhorky commented May 10, 2023

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
Copy link
Contributor

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.

@berekuk
Copy link
Contributor

berekuk commented May 10, 2023

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

Not in my case.

My setup is a yarn-based monorepo with turbo, Relay, and v13 app router (mostly with use client, because of Relay).

Also, for me, this error is somewhat random, it depends on the build in Vercel, or maybe on a particular serverless function deployment. It's really weird.

For example, the images below are for the same git commit, first deployed to the branch, and then pushed to the production with "Promote to Production" button in Vercel.

Right now, quri-khfninxe4-quantified-uncertainty (initial domain for the preview branch) works, while other domains return 500, with this error in logs.

Captura de pantalla 2023-05-10 a la(s) 8 30 17 Captura de pantalla 2023-05-10 a la(s) 8 30 05

Maybe it's caused by turborepo caches? Though I'm pretty sure I've also had non-cached deployments that failed. But, just in case it matters, my turbo.json has "outputs": [".next/**", "../../node_modules/.prisma"].

@shuding shuding reopened this May 11, 2023
@ugurnarin
Copy link

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.

@markky21
Copy link

Upgrade to 13.5.2 fix worked also for me. However, this caused a problem with Storybook. Discussion is here

@jbothma
Copy link

jbothma commented Sep 22, 2023

Upgrading to 13.5.1 and 13.5.2 gives me this error, not yet sure if it's in my code or some dependency

✓ Compiled successfully
--
04:48:01.978 | Linting and checking validity of types...
04:48:14.463 | Collecting page data...
04:48:15.447 | TypeError: Cannot create property 'propTypes' on number 'Infinity'
04:48:15.449 | at 58374 (/vercel/path1/.next/server/chunks/7497.js:9:1088735)
04:48:15.450 | at t (/vercel/path1/.next/server/webpack-runtime.js:1:127)
04:48:15.450 | at 14060 (/vercel/path1/.next/server/chunks/5146.js:13:7137)
04:48:15.451 | at t (/vercel/path1/.next/server/webpack-runtime.js:1:127)
04:48:15.451 | at 99725 (/vercel/path1/.next/server/chunks/5146.js:13:5485)
04:48:15.451 | at Function.t (/vercel/path1/.next/server/webpack-runtime.js:1:127)
04:48:15.451 | at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
04:48:15.451 | at async collectGenerateParams (/vercel/path1/node_modules/next/dist/build/utils.js:859:17)
04:48:15.451 |  
04:48:15.452 | > Build error occurred
04:48:15.452 | Error: Failed to collect page data for /_not-found
04:48:15.452 | at /vercel/path1/node_modules/next/dist/build/utils.js:1195:15
04:48:15.452 | at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
04:48:15.452 | type: 'Error'
04:48:15.453 | }

@wan2land
Copy link
Contributor

wan2land commented Sep 22, 2023

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

@aziznal-ch
Copy link

Upgrading to 13.5.2 worked for me as well.

@zetorama
Copy link

Curious to understand what caused this issue to appear on vercel today, so we can learn how to mitigate something similar in future. Could it be related to the recent update of react canary?

@MujtabaPro1
Copy link

Updating version to 13.5.2 worked for me

@nisithaD
Copy link

Updating version to 13.5.2 worked for me.

@kenshanta
Copy link

kenshanta commented Sep 22, 2023

updating to next => 13.5.2 did the trick

@jbothma
Copy link

jbothma commented Sep 22, 2023

@zetorama I would like to know what Vercel is going to do about QA of Vercel CLI upgrades vercel/vercel#10564

I'd prefer not to have to pin vercel CLI version but at the moment it looks wise to do so to avoid surprises like this affecting production without changes on our side.

@jbothma
Copy link

jbothma commented Sep 22, 2023

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.

@tiwariaditya15
Copy link

upgrading to next 13.5.2 fixed this for me.

@VladSez
Copy link

VladSez commented Sep 22, 2023

UPD: another solution to this issue (besides updating to latest next version) is to set the env var [email protected] on vercel
More info: vercel/vercel#10564

@AhmedBaset
Copy link
Contributor

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?

@oliveirabruno01
Copy link

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?

Same here. Re-building old builds is not working. But there's a old deploy I can access on vercel and it's working. If I try to deploy this same commit it just don't work on the new deploy.

Updating next to 13.5.2 didn't fix it.

@oliveirabruno01
Copy link

UPD: another solution to this issue (besides updating to latest next version) is to set the env var [email protected] on vercel More info: vercel/vercel#10564

This did the trick to me. Thanks!

@ktcarter
Copy link

ktcarter commented Sep 22, 2023

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

@programm-ingovals
Copy link

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

But what if we get this error when we are not using vercel, just running using node, and version 13.5.3 of Next.
Does anyone know what this error actually is. Why is Next.js looking for a server.edge export from React-dom, isn't edge functions Nextjs specific?

@victor-pagnozi
Copy link

Upgrading to 13.5.2 and fixed it to me!

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. locked
Projects
None yet