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

Missing node_modules in standalone output #56357

Closed
1 task done
noreiller opened this issue Oct 3, 2023 · 21 comments · Fixed by #56674
Closed
1 task done

Missing node_modules in standalone output #56357

noreiller opened this issue Oct 3, 2023 · 21 comments · Fixed by #56674
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. locked Output (export/standalone) Related to the the output option in `next.config.js`.

Comments

@noreiller
Copy link
Contributor

noreiller commented Oct 3, 2023

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

@noreiller noreiller added the bug Issue was opened via the bug report template. label Oct 3, 2023
@github-actions github-actions bot added the Output (export/standalone) Related to the the output option in `next.config.js`. label Oct 3, 2023
@peakercope
Copy link

+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 }

pietrobondioli added a commit to pietrobondioli/mywebsite-nextjs that referenced this issue Oct 3, 2023
@octavioamu
Copy link

Related but on next-i18next repo i18next/next-i18next#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'

pietrobondioli added a commit to pietrobondioli/mywebsite-nextjs that referenced this issue Oct 3, 2023
@rwieruch
Copy link
Contributor

rwieruch commented Oct 4, 2023

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

@peakercope
Copy link

Related but on next-i18next repo i18next/next-i18next#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'

It works locally because of node.js resolution algorithm of node_modules. Try to move .next/standalone folder somewhere outside your project (e.g. in /home or /tmp directory) and you will get this error.

@eswolters
Copy link

Same here had to downgrade to 13.5.3

@vashian
Copy link

vashian commented Oct 4, 2023

I encountered the same issue while using Next.js version 13.5.4.

"Error: Cannot locate the module 'core-js/modules/es.array.map.js'."

@isaackoz
Copy link

isaackoz commented Oct 4, 2023

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

@nbouvrette
Copy link
Contributor

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'
}

@lhguerra
Copy link

lhguerra commented Oct 5, 2023

also had to downgrade

@pablojsx
Copy link

pablojsx commented Oct 6, 2023

Log from Vercel:

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'lodash.mapkeys' imported from /var/task/node_modules/@nextui-org/theme/dist/chunk-RYOZQSNI.mjs

It works in localhost only: https://ezpizza-next.vercel.app/menu

The server side code:

export async function getServerSideProps(ctx: GetServerSidePropsContext) { try { const menu = await getMenu(); return { props: { menu } }; } catch { return { props: { menu: [], error: { message: "Couldn't get the menu." } } }; } }

@pablojsx
Copy link

pablojsx commented Oct 6, 2023

Ok I downgraded to 13.5.3 and it worked

@samtgarson
Copy link

I'm also experiencing missing sharp on one project and core-js on another project when upgrading to 13.5.4, only on Vercel. Downgrading does fix however I'm unable to do so because there are other critical bugs in lower 13.5.x versions (links not navigating correctly).

Strangely, I'm not using output: standalone. Is anyone else on this thread experiencing this issue without that option enabled?

@ajturpei
Copy link

ajturpei commented Oct 8, 2023

Getting the exact same issue on getstaticprops with revalidate (isr) and getserversideprops when deployed to Vercel. Works flawlessly on local. Version 13.5.4 with next-i18next

"Error: Cannot locate the module 'core-js/modules/es.array.map.js'."

@balazsorban44 balazsorban44 added the linear: next Confirmed issue that is tracked by the Next.js team. label Oct 9, 2023
@fescherer
Copy link

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",

@kodiakhq kodiakhq bot closed this as completed in #56674 Oct 10, 2023
kodiakhq bot pushed a commit that referenced this issue Oct 10, 2023
This ensures we separate our ignore handling for next-server runtime entries and `.next/server` chunks. When these were combined our ignores caused modules that should were actually needed by user code to be excluded. 

Verified patch against the provided minimal repros

![CleanShot 2023-10-10 at 11 56 36@2x](https://github.com/vercel/next.js/assets/22380829/1dd83996-fa95-462a-98ed-485ce6c4d3f5)

![CleanShot 2023-10-10 at 12 01 08@2x](https://github.com/vercel/next.js/assets/22380829/c17c6147-0e3e-422b-bf2d-5fedfd6827ef)


x-ref: #56048 (comment)
Fixes: #56357
@Abdulrahmanelheyb
Copy link

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

@gmcamposano
Copy link

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

@ykzts
Copy link
Contributor

ykzts commented Oct 16, 2023

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.

0916dhkim added a commit to 0916dhkim/bingo that referenced this issue Oct 16, 2023
@Abdulrahmanelheyb
Copy link

Abdulrahmanelheyb commented Oct 16, 2023

No report about this error? Why is it caused?

@mozzius
Copy link

mozzius commented Oct 16, 2023

Appears to be working in next@13.5.5

@ucefkh
Copy link

ucefkh commented Oct 22, 2023

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

Copy link
Contributor

github-actions bot commented Nov 5, 2023

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 added the locked label Nov 5, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 5, 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 Output (export/standalone) Related to the the output option in `next.config.js`.
Projects
None yet
Development

Successfully merging a pull request may close this issue.