next.js: Missing node_modules in standalone output

Link to the code that reproduces this issue

https://github.com/noreiller/next-missing-modules-in-standalone-pages

To Reproduce

  1. Run npm i
  2. Run npm i next@13.5.4-canary.4
  3. Run npm run build
  4. See that the directory .next/standalone/node_modules/@kontent-ai/delivery-sdk/dist/cjs/mappers only contains the index.js file.

Current vs. Expected behavior

Starting from v13.5.4-canary.4, the directory .next/standalone/node_modules/@kontent-ai/delivery-sdk/dist/cjs/mappers only contains the index.js file while previously it contained all the required modules used in the index.js file.

Verify canary release

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

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #33~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Sep  7 10:33:52 UTC 2
Binaries:
  Node: 18.12.1
  npm: 8.19.2
  Yarn: 1.22.19
  pnpm: 8.2.0
Relevant Packages:
  next: 13.5.4
  eslint-config-next: 13.5.4
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2
Next.js Config:
  output: standalone

Which area(s) are affected? (Select all that apply)

Standalone mode (output: “standalone”)

Additional context

In node_modules: image

In .next/standalone/node_modules: image

NEXT-1675

About this issue

  • Original URL
  • State: closed
  • Created 9 months ago
  • Reactions: 19
  • Comments: 21 (4 by maintainers)

Commits related to this issue

Most upvoted comments

+1 Faced the same issue with next-i18next package.

To reproduce:

Actual result: 500 Internal Server Error in browser

Error in docker logs

2023-10-03 17:16:52 Error: Cannot find module 'core-js/modules/es.array.map.js'
2023-10-03 17:16:52 Require stack:
2023-10-03 17:16:52 - /app/node_modules/next-i18next/dist/commonjs/config/createConfig.js
2023-10-03 17:16:52 - /app/node_modules/next-i18next/dist/commonjs/appWithTranslation.js
2023-10-03 17:16:52 - /app/node_modules/next-i18next/dist/commonjs/index.js
2023-10-03 17:16:52 - /app/.next/server/pages/_app.js
2023-10-03 17:16:52 - /app/node_modules/next/dist/server/require.js
2023-10-03 17:16:52 - /app/node_modules/next/dist/server/next-server.js
2023-10-03 17:16:52 - /app/node_modules/next/dist/server/next.js
2023-10-03 17:16:52 - /app/server.js
2023-10-03 17:16:52     at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
2023-10-03 17:16:52     at /app/node_modules/next/dist/server/require-hook.js:54:36
2023-10-03 17:16:52     at Module._load (node:internal/modules/cjs/loader:922:27)
2023-10-03 17:16:52     at Module.require (node:internal/modules/cjs/loader:1143:19)
2023-10-03 17:16:52     at mod.require (/app/node_modules/next/dist/server/require-hook.js:64:28)
2023-10-03 17:16:52     at require (node:internal/modules/cjs/helpers:119:18)
2023-10-03 17:16:52     at Object.<anonymous> (/app/node_modules/next-i18next/dist/commonjs/config/createConfig.js:35:1)
2023-10-03 17:16:52     at Module._compile (node:internal/modules/cjs/loader:1256:14)
2023-10-03 17:16:52     at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
2023-10-03 17:16:52     at Module.load (node:internal/modules/cjs/loader:1119:32) {
2023-10-03 17:16:52   code: 'MODULE_NOT_FOUND',
2023-10-03 17:16:52   requireStack: [
2023-10-03 17:16:52     '/app/node_modules/next-i18next/dist/commonjs/config/createConfig.js',
2023-10-03 17:16:52     '/app/node_modules/next-i18next/dist/commonjs/appWithTranslation.js',
2023-10-03 17:16:52     '/app/node_modules/next-i18next/dist/commonjs/index.js',
2023-10-03 17:16:52     '/app/.next/server/pages/_app.js',
2023-10-03 17:16:52     '/app/node_modules/next/dist/server/require.js',
2023-10-03 17:16:52     '/app/node_modules/next/dist/server/next-server.js',
2023-10-03 17:16:52     '/app/node_modules/next/dist/server/next.js',
2023-10-03 17:16:52     '/app/server.js'
2023-10-03 17:16:52   ]
2023-10-03 17:16:52 }

Related but on next-i18next repo https://github.com/i18next/next-i18next/issues/2214 In that package the problem happens when using getServerSideProps and serverSideTranslations the pages with getStaticProps and serverSideTranslations works fine. Running build locally works fine only fails on vercel reporting missing module Error: Cannot find module ‘core-js/modules/es.array.map.js’

Appears to be working in next@13.5.5

Can confirm. I had to downgraade to yarn add -E next@13.5.3

I am having the same issue. In dev (local) mode works fine, but when deployed to Vercel gives the 505 error. I had:

"react": "^18.2.0",
"next": "^13.5.3",
"i18next": "^23.5.1",
"next-i18next": "^14.0.3",
"react-i18next": "^13.2.2",

Removing the ^ in the Next dependency worked.

"react": "^18.2.0",
"next": "13.5.3",
"i18next": "^23.5.1",
"next-i18next": "^14.0.3",
"react-i18next": "^13.2.2",

Getting the same with sharp on 13.5.4 deployed on Vercel. Error: Cannot find module 'sharp'

Edit: Downgrading to 13.5.3 fixed the issue. This only happened on pages using Plaiceholder. I had sharp installed via npm install sharp, but still was having issues. Is this an issue with packages included with Next by default? If I’m not mistaken, Next automatically includes sharp correct? Is there some conflicting issues with packages that depend on these packages included by Next? I.E. Plaiceholder depends on sharp and can’t seem to find it.

Issue seems to come from #56048

Next 13.5.6 came out but seems a shame there was no reactivity on this issue or at least a word!

This Issue has not been stable released but has been fixed in canary. We need to wait for next@13.5.5 or next@13.6.0.

Still getting the issue with sharp on version 13.5.4 only running on vercel. I works correctly on development, but fails on production. Had to downgrade as well to 13.5.3

I get the same error when deploying on the container locally for test Error: Cannot find module 'core-js/modules/es.array.map.js' image Currently, I have downgraded to nextjs@13.5.3

Same issue - both the dev and build works locally, but when deploying on Vercel:

Error: Cannot find module 'sharp'
Require stack:
- /var/task/.next/server/pages/some-page.js
- /var/task/node_modules/next/dist/server/require.js
- /var/task/node_modules/next/dist/server/next-server.js
- /var/task/___next_launcher.cjs
    at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
    at /var/task/node_modules/next/dist/server/require-hook.js:54:36
    at Module._load (node:internal/modules/cjs/loader:922:27)
    at Ze.e.<computed>._module.Module._load (/var/task/___vc/__launcher/__launcher.js:14:1964)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at mod.require (/var/task/node_modules/next/dist/server/require-hook.js:64:28)
    at require (node:internal/modules/cjs/helpers:121:18)
    at 59551 (/var/task/.next/server/pages/some-page.js:1:64829)
    at __webpack_require__ (/var/task/.next/server/webpack-runtime.js:1:146)
    at __webpack_exec__ (/var/task/.next/server/pages/some-page.js:1:70871) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/var/task/.next/server/pages/some-page.js',
    '/var/task/node_modules/next/dist/server/require.js',
    '/var/task/node_modules/next/dist/server/next-server.js',
    '/var/task/___next_launcher.cjs'
  ],
  page: '/some-page'
}