next.js: Build occasionally fails complains about missing modules but also succeeds
Bug report
Describe the bug
I have a fairly simple app that pings a mongo database and generates dynamic pages. The homepage lists a handful of documents and they link to individual pages. The build often fails complaining about missing modules despite running perfectly fine on localhost. However, if I build it a 2nd or 3rd time it will usually succeed.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
- Clone https://github.com/itsclarke/vantures
- Install dependencies
- Run
npm run dev
- While dev is running, also run
npm run build
- See errors
Expected behavior
A failed build outputs:
> next build
info - Loaded env from ~/app/.env.local
Creating an optimized production build
Compiled successfully.
Automatically optimizing pages .
Error occurred prerendering page "/rental/new". Read more: https://err.sh/next.js/prerender-error
Error: Cannot find module for page: /rental/new
at pageNotFoundError (~/app/node_modules/next/dist/next-server/server/require.js:1:384)
at getPagePath (~/app/node_modules/next/dist/next-server/server/require.js:2:82)
at requirePage (~/app/node_modules/next/dist/next-server/server/require.js:2:227)
at loadComponents (~/app/node_modules/next/dist/next-server/server/load-components.js:1:771)
at Object.exportPage [as default] (~/app/node_modules/next/dist/export/worker.js:14:188)
Error occurred prerendering page "/rental/10051164". Read more: https://err.sh/next.js/prerender-error
Error: Cannot find module for page: /rental/[id]
at pageNotFoundError (~/app/node_modules/next/dist/next-server/server/require.js:1:384)
at getPagePath (~/app/node_modules/next/dist/next-server/server/require.js:2:82)
at requirePage (~/app/node_modules/next/dist/next-server/server/require.js:2:227)
at loadComponents (~/app/node_modules/next/dist/next-server/server/load-components.js:1:771)
at Object.exportPage [as default] (~/app/node_modules/next/dist/export/worker.js:14:188)
Error occurred prerendering page "/rental/10082307". Read more: https://err.sh/next.js/prerender-error
Error: Cannot find module for page: /rental/[id]
at pageNotFoundError (~/app/node_modules/next/dist/next-server/server/require.js:1:384)
at getPagePath (~/app/node_modules/next/dist/next-server/server/require.js:2:82)
at requirePage (~/app/node_modules/next/dist/next-server/server/require.js:2:227)
at loadComponents (~/app/node_modules/next/dist/next-server/server/load-components.js:1:771)
at Object.exportPage [as default] (~/app/node_modules/next/dist/export/worker.js:14:188)
Error occurred prerendering page "/rental/10138784". Read more: https://err.sh/next.js/prerender-error
Error: Cannot find module for page: /rental/[id]
at pageNotFoundError (~/app/node_modules/next/dist/next-server/server/require.js:1:384)
at getPagePath (~/app/node_modules/next/dist/next-server/server/require.js:2:82)
at requirePage (~/app/node_modules/next/dist/next-server/server/require.js:2:227)
at loadComponents (~/app/node_modules/next/dist/next-server/server/load-components.js:1:771)
at Object.exportPage [as default] (~/app/node_modules/next/dist/export/worker.js:14:188)
Error occurred prerendering page "/rental/10057826". Read more: https://err.sh/next.js/prerender-error
Error: Cannot find module for page: /rental/[id]
at pageNotFoundError (~/app/node_modules/next/dist/next-server/server/require.js:1:384)
at getPagePath (~/app/node_modules/next/dist/next-server/server/require.js:2:82)
at requirePage (~/app/node_modules/next/dist/next-server/server/require.js:2:227)
at loadComponents (~/app/node_modules/next/dist/next-server/server/load-components.js:1:771)
at Object.exportPage [as default] (~/app/node_modules/next/dist/export/worker.js:14:188)
Error occurred prerendering page "/rental/10059872". Read more: https://err.sh/next.js/prerender-error
Error: Cannot find module for page: /rental/[id]
at pageNotFoundError (~/app/node_modules/next/dist/next-server/server/require.js:1:384)
at getPagePath (~/app/node_modules/next/dist/next-server/server/require.js:2:82)
at requirePage (~/app/node_modules/next/dist/next-server/server/require.js:2:227)
at loadComponents (~/app/node_modules/next/dist/next-server/server/load-components.js:1:771)
at Object.exportPage [as default] (~/app/node_modules/next/dist/export/worker.js:14:188)
Error occurred prerendering page "/". Read more: https://err.sh/next.js/prerender-error
Error: Cannot find module for page: /
at pageNotFoundError (~/app/node_modules/next/dist/next-server/server/require.js:1:384)
at getPagePath (~/app/node_modules/next/dist/next-server/server/require.js:2:82)
at requirePage (~/app/node_modules/next/dist/next-server/server/require.js:2:227)
at loadComponents (~/app/node_modules/next/dist/next-server/server/load-components.js:1:771)
at Object.exportPage [as default] (~/app/node_modules/next/dist/export/worker.js:14:188)
> Build error occurred
Error: Export encountered errors on following paths:
/
/rental/10051164
/rental/10057826
/rental/10059872
/rental/10082307
/rental/10138784
/rental/new
at exportApp (~/app/node_modules/next/dist/export/index.js:24:1103)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async build (~/app/node_modules/next/dist/build/index.js:37:218)
When it succeeds the build outputs:
info - Loaded env from /Users/brianclarke/Documents/development/next-vanture/.env.local
Creating an optimized production build
Compiled successfully.
Automatically optimizing pages .Could not find files for /rental/new in .next/build-manifest.json
Automatically optimizing pages ..Could not find files for /rental/[id] in .next/build-manifest.json
Automatically optimizing pages
Page Size First Load JS
┌ ● / 3.89 kB 62.7 kB
├ /_app 0 B 58.8 kB
├ ○ /404 3.02 kB 61.9 kB
├ λ /api/rental/[id] 0 B 58.8 kB
├ λ /api/rental/new 0 B 58.8 kB
├ λ /api/results 0 B 58.8 kB
├ ● /rental/[id] 1.42 kB 60.2 kB
├ ├ /rental/10059872
├ ├ /rental/10051164
├ ├ /rental/10082307
├ └ [+2 more paths]
└ ○ /rental/new 54.2 kB 113 kB
+ First Load JS shared by all 58.8 kB
├ chunks/commons.90eb9f.js 10.2 kB
├ chunks/framework.9862e0.js 40.5 kB
├ chunks/main.68a017.js 6.73 kB
├ chunks/pages/_app.7abee3.js 280 B
├ chunks/webpack.f300b4.js 1.19 kB
└ css/fafd01249af2219e34a0.css 194 B
λ (Server) server-side renders at runtime (uses getInitialProps or getServerSideProps)
○ (Static) automatically rendered as static HTML (uses no initial props)
● (SSG) automatically generated as static HTML + JSON (uses getStaticProps)
Redirects
┌ source: /:path+/
├ destination: /:path+
└ permanent: true
But the other server running the API code outputs this as well:
the options [servers] is not supported
the options [caseTranslate] is not supported
the options [dbName] is not supported
the options [srvHost] is not supported
the options [credentials] is not supported
the options [servers] is not supported
the options [caseTranslate] is not supported
the options [dbName] is not supported
the options [srvHost] is not supported
the options [credentials] is not supported
the options [username] is not supported
the server/replset/mongos/db options are deprecated, all their options are supported at the top level of the options object [poolSize,ssl,sslValidate,sslCA,sslCert,sslKey,sslPass,sslCRL,autoReconnect,noDelay,keepAlive..
System information
- OS: macOS
- Version of Next.js: 9.5.1
- Version of Node.js: 14.5.0
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 7
- Comments: 24 (1 by maintainers)
@touqeeraslam I haven’t been able to solve it. Ended up not using NextJS because the contributors never got back to me.
Any idea on how one would go about fixing this?
hey guys! I have the exact same issue with mongo. Moreover I can’t compile “next project” on my production server, but able to compile it on local dev-pc. Any thoughts ?
Same problem with deploying to S3 using Github Actions
any update on this issue, please?
Hi!, I’m having the same problem, did you find a way to solve it?
Hello All,
Last 24 Hours i was stocked on this issue. i solved this problem removing the non page component from the page folder in the project.
hey guys!! I have encountered same issue. In my case when i remove cacheDirectories param in package.json. The build succeeded. It can be because any issue but it helped me resolve the issue for now. I will debug further and will let y’all know if i find anything