nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.62k stars 2.36k forks source link

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

Closed MRezaSafari closed 1 year ago

MRezaSafari commented 1 year ago

Current Behavior

Receiveing error

event - compiled client and server successfully in 2.8s (684 modules) wait - compiling... [ ready ] on http://localhost:4200 event - compiled client and server successfully in 1296 ms (684 modules) wait - compiling /page (client and server)... event - compiled client and server successfully in 18.8s (8718 modules) wait - compiling... error - Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './server.edge' is not defined by "exports" in /Users/m/Development/XX/Frontend/node_modules/react-dom/package.json

Expected Behavior

run successfuly

GitHub Repo

No response

Steps to Reproduce

  1. upgrade nextjs to 13.3.4

Nx Report

Node   : 16.18.0
   OS     : darwin arm64
   yarn   : 1.22.19
   Hasher : Native

   nx                 : 16.0.1
   @nx/js             : 16.0.1
   @nx/jest           : 16.0.1
   @nx/linter         : 16.0.1
   @nx/workspace      : 16.0.1
   @nx/cypress        : 16.0.1
   @nx/devkit         : 16.0.1
   @nx/eslint-plugin  : 16.0.1
   @nx/next           : 16.0.1
   @nx/react          : 16.0.1
   @nx/storybook      : 16.0.1
   @nrwl/tao          : 16.0.1
   @nx/web            : 16.0.1
   nx-cloud           : 16.0.5
   typescript         : 5.0.4

Failure Logs

error - Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './server.edge' is not defined by "exports" in /Users/reza/Development/Legamart/Frontend/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:522:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:562:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:971:27)
    at /Users/reza/Development/Legamart/Frontend/node_modules/next/dist/server/require-hook.js:180:36
    at Function.Module._load (node:internal/modules/cjs/loader:833:27)
    at Module.require (node:internal/modules/cjs/loader:1057:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/Users/reza/Development/Legamart/Frontend/node_modules/next/dist/server/app-render/app-render.js:24:60)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12)
    at Module.require (node:internal/modules/cjs/loader:1057:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at DevServer.renderHTMLImpl (/Users/reza/Development/Legamart/Frontend/node_modules/next/dist/server/next-server.js:674:72)
    at /Users/reza/Development/Legamart/Frontend/node_modules/next/dist/server/next-server.js:664:105
    at NextTracerImpl.trace (/Users/reza/Development/Legamart/Frontend/node_modules/next/dist/server/lib/trace/tracer.js:86:20)
    at DevServer.renderHTML (/Users/reza/Development/Legamart/Frontend/node_modules/next/dist/server/next-server.js:664:41)
    at doRender (/Users/reza/Development/Legamart/Frontend/node_modules/next/dist/server/base-server.js:1022:45)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async cacheEntry.responseCache.get.incrementalCache.incrementalCache (/Users/reza/Development/Legamart/Frontend/node_modules/next/dist/server/base-server.js:1145:28)
    at async /Users/reza/Development/Legamart/Frontend/node_modules/next/dist/server/response-cache/index.js:97:36 {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED',
  page: '/'
}

Additional Information

No response

jaysoo commented 1 year ago

@MRezaSafari Is this with pages or appDir? What versions of react and react-dom are you on?

jaysoo commented 1 year ago

Does setting __NEXT_PRIVATE_PREBUNDLED_REACT=next environment variable help? as some are suggesting here https://github.com/vercel/next.js/issues/49169.

mhar-andal commented 1 year ago

I can confirm that the environment variable above is working for next@13.4.1 and @nx@16.1. Thanks @jaysoo !

Edit: this is with appDir and react@18.2.0

leon-marzahn commented 1 year ago

Is there a way to fix this without needing the environment variable?

jaysoo commented 1 year ago

@mhar-andal Thanks for verifying. This is the workaround for now. You can set it in your next.config.js or .env file.

#.env

# or 'experimental' if serverActions is enabled
__NEXT_PRIVATE_PREBUNDLED_REACT=next

Edit: Setting in next.config.js is too late and will cause two different React renderers to load. Use .env instead.

We are preparing for the Nx 16.2.0 release, which will come with Next.js 13.4 by default and fix issues like this by invoking the Next.js CLI directly.

szkabaroli commented 1 year ago

@jaysoo Thanks a lot. It's working for me using a .env file.

tholder commented 1 year ago

happens on netlify with 13.4.1 and can't set __NEXT_PRIVATE_PREBUNDLEDREACT=next because it starts with

marianzburlea commented 1 year ago

I get the same as @tholder

May 6, 01:36:27 PM: b8e6b8e3 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'
}May 6, 01:36:27 PM: b8e6b8e3 INFO   [GET] / (SSR)May 6, 01:36:27 PM: b8e6b8e3 Duration: 100.46 ms  Memory Usage: 137 MB    
image
Anerco commented 1 year ago

fixed on 16.1.1. thanks everyone!

github-actions[bot] commented 1 year ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.