vercel / next.js

The React Framework
https://nextjs.org
MIT License
124.69k stars 26.62k forks source link

Build occasionally fails complains about missing modules but also succeeds #15874

Open itsclarke opened 4 years ago

itsclarke commented 4 years ago

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:

  1. Clone https://github.com/itsclarke/vantures
  2. Install dependencies
  3. Run npm run dev
  4. While dev is running, also run npm run build
  5. 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

squarecylinder commented 4 years ago

I can't seem to get the same errors as you, however I can't get a successful build either. Running npm run dev prints out

> next-vanture@0.1.0 dev C:\Users\amber\Desktop\opensource_help\vantures
> next dev -p 8080

ready - started server on http://localhost:8080
event - compiled successfully
event - build page: /api/results
wait  - compiling...
event - compiled successfully
(node:28452) UnhandledPromiseRejectionWarning: RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: ENOTFOUND
    at ServerResponse.writeHead (_http_server.js:249:11)
    at ServerResponse.writeHead (C:\Users\amber\Desktop\opensource_help\vantures\node_modules\next\dist\compiled\compression\index.js:1:144825)
    at ServerResponse._implicitHeader (_http_server.js:240:8)
    at ServerResponse.end (C:\Users\amber\Desktop\opensource_help\vantures\node_modules\next\dist\compiled\compression\index.js:1:148771)
    at onerror (C:\Users\amber\Desktop\opensource_help\vantures\node_modules\next-connect\lib\index.js:5:7)
    at next (C:\Users\amber\Desktop\opensource_help\vantures\node_modules\next-connect\lib\index.js:66:13)
    at next (C:\Users\amber\Desktop\opensource_help\vantures\node_modules\next-connect\lib\index.js:68:19)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:28452) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:28452) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Running npm run build prints out

> next-vanture@0.1.0 build C:\Users\amber\Desktop\opensource_help\vantures
> next build

Creating an optimized production build

Compiled successfully.

> Build error occurred
Error [FetchError]: request to http://localhost:8080/api/results failed, reason: read ECONNRESET
    at ClientRequest.<anonymous> (C:\Users\amber\Desktop\opensource_help\vantures\node_modules\isomorphic-fetch\node_modules\node-fetch\index.js:133:11)
    at ClientRequest.emit (events.js:314:20)
    at Socket.socketErrorListener (_http_client.js:469:9)
    at Socket.emit (events.js:314:20)
    at emitErrorNT (internal/streams/destroy.js:100:8)
    at emitErrorCloseNT (internal/streams/destroy.js:68:3)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  type: 'system',
  errno: 'ECONNRESET',
  code: 'ECONNRESET'
}
Automatically optimizing pages .npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! next-vanture@0.1.0 build: `next build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the next-vanture@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\amber\AppData\Roaming\npm-cache\_logs\2020-08-04T17_52_13_075Z-debug.log

This is what the logs show

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'build'
1 verbose cli ]
2 info using npm@6.14.5
3 info using node@v14.5.0
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle next-vanture@0.1.0~prebuild: next-vanture@0.1.0
6 info lifecycle next-vanture@0.1.0~build: next-vanture@0.1.0
7 verbose lifecycle next-vanture@0.1.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle next-vanture@0.1.0~build: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\amber\Desktop\opensource_help\vantures\node_modules\.bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\amber\bin;C:\Python38\Scripts;C:\Python38;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Intel\WiFi\bin;C:\Program Files\Common Files\Intel\WirelessCommon;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Git\cmd;C:\Program Files\MongoDB\Server\4.2\bin;C:\Program Files\nodejs;C:\ProgramData\chocolatey\bin;C:\Users\amber\AppData\Local\Microsoft\WindowsApps;C:\Users\amber\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\amber\AppData\Local\GitHubDesktop\bin;C:\Program Files\heroku\bin;C:\Users\amber\AppData\Local\Microsoft\WindowsApps;C:\Users\amber\AppData\Roaming\npm
9 verbose lifecycle next-vanture@0.1.0~build: CWD: C:\Users\amber\Desktop\opensource_help\vantures
10 silly lifecycle next-vanture@0.1.0~build: Args: [ '/d /s /c', 'next build' ]
11 silly lifecycle next-vanture@0.1.0~build: Returned: code: 1  signal: null
12 info lifecycle next-vanture@0.1.0~build: Failed to exec build script
13 verbose stack Error: next-vanture@0.1.0 build: `next build`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:314:20)
13 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:314:20)
13 verbose stack     at maybeClose (internal/child_process.js:1051:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
14 verbose pkgid next-vanture@0.1.0
15 verbose cwd C:\Users\amber\Desktop\opensource_help\vantures
16 verbose Windows_NT 10.0.18363
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
18 verbose node v14.5.0
19 verbose npm  v6.14.5
20 error code ELIFECYCLE
21 error errno 1
22 error next-vanture@0.1.0 build: `next build`
22 error Exit status 1
23 error Failed at the next-vanture@0.1.0 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

Other things to note, I was never able to get the mongodb collection showing up either. System information

saswatamcode commented 4 years ago

I managed to recreate the errors mentioned in the issue. Upon running npm run dev:

> next-vanture@0.1.0 dev /Users/saswatamukherjee/web/vantures
> next dev -p 8080

ready - started server on http://localhost:8080
event - compiled successfully
event - build page: /
wait  - compiling...
event - compiled successfully
event - build page: /api/results
wait  - compiling...
event - compiled successfully
event - build page: /api/results
wait  - compiling...
event - compiled successfully

Upon running npm run build and build fails:

> next-vanture@0.1.0 build /Users/saswatamukherjee/web/vantures
> next build

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 (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/require.js:1:384)
    at getPagePath (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/require.js:2:82)
    at requirePage (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/require.js:2:227)
    at loadComponents (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/load-components.js:1:771)
    at Object.exportPage [as default] (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/export/worker.js:14:188)

> Build error occurred
Error: Export encountered errors on following paths:
        /rental/new
    at exportApp (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/export/index.js:24:1103)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async build (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/build/index.js:37:218)
Automatically optimizing pages .npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! next-vanture@0.1.0 build: `next build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the next-vanture@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/saswatamukherjee/.npm/_logs/2020-08-06T13_54_10_024Z-debug.log

Upon running npm run dev and build fails but this time error shows two routes instead of one:

> next-vanture@0.1.0 build /Users/saswatamukherjee/web/vantures
> next build

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 (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/require.js:1:384)
    at getPagePath (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/require.js:2:82)
    at requirePage (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/require.js:2:227)
    at loadComponents (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/load-components.js:1:771)
    at Object.exportPage [as default] (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/export/worker.js:14:188)

Error occurred prerendering page "/". Read more: https://err.sh/next.js/prerender-error
FetchError: request to http://localhost:8080/api/results failed, reason: connect ECONNREFUSED 127.0.0.1:8080
    at ClientRequest.<anonymous> (/Users/saswatamukherjee/web/vantures/node_modules/isomorphic-fetch/node_modules/node-fetch/index.js:133:11)
    at ClientRequest.emit (events.js:315:20)
    at Socket.socketErrorListener (_http_client.js:426:9)
    at Socket.emit (events.js:315:20)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)

> Build error occurred
Error: Export encountered errors on following paths:
        /
        /rental/new
    at exportApp (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/export/index.js:24:1103)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async build (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/build/index.js:37:218)
Automatically optimizing pages .npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! next-vanture@0.1.0 build: `next build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the next-vanture@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/saswatamukherjee/.npm/_logs/2020-08-06T13_48_04_823Z-debug.log

Upon running npm run build and build succeeds:

> next-vanture@0.1.0 build /Users/saswatamukherjee/web/vantures
> next build

Creating an optimized production build  

Compiled successfully.

Automatically optimizing pages  

Page                              Size     First Load JS
┌ ● /                             3.89 kB        62.9 kB
├   /_app                         0 B              59 kB
├ ○ /404                          3.03 kB          62 kB
├ λ /api/rental/[id]              0 B              59 kB
├ λ /api/rental/new               0 B              59 kB
├ λ /api/results                  0 B              59 kB
├ ● /rental/[id]                  1.42 kB        60.4 kB
└ ○ /rental/new                   52.6 kB         112 kB
+ First Load JS shared by all     59 kB
  ├ chunks/commons.5f7a56.js      10.2 kB
  ├ chunks/framework.1beee9.js    40.6 kB
  ├ chunks/main.cbe33c.js         6.73 kB
  ├ chunks/pages/_app.c4b3a7.js   280 B
  ├ chunks/webpack.f300b4.js      1.19 kB
  └ css/52b58017dc61730a05c9.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

Also as mentioned above the mongodb collection doesn't show. I did change the url to a localhost one. Maybe this has something to do a missing prop in rental/new.js?

System Information:

itsclarke commented 4 years ago

@squarecylinder @saswatamcode go ahead a do a fresh pull and try again please. I hard coded my mongo credentials and whitelisted all IPs.

saswatamcode commented 4 years ago

I did a fresh pull. Now, I'm getting data in the application and your initial error does appear exactly as in when running npm run build.

> next-vanture@0.1.0 build /Users/saswatamukherjee/web/vantures
> next build

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 (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/require.js:1:384)
    at getPagePath (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/require.js:2:82)
    at requirePage (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/require.js:2:227)
    at loadComponents (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/load-components.js:1:771)
    at Object.exportPage [as default] (/Users/saswatamukherjee/web/vantures/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 (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/require.js:1:384)
    at getPagePath (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/require.js:2:82)
    at requirePage (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/require.js:2:227)
    at loadComponents (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/load-components.js:1:771)
    at Object.exportPage [as default] (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/export/worker.js:14:188)
Automatically optimizing pages ...
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 (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/require.js:1:384)
    at getPagePath (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/require.js:2:82)
    at requirePage (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/require.js:2:227)
    at loadComponents (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/load-components.js:1:771)
    at Object.exportPage [as default] (/Users/saswatamukherjee/web/vantures/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 (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/require.js:1:384)
    at getPagePath (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/require.js:2:82)
    at requirePage (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/require.js:2:227)
    at loadComponents (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/load-components.js:1:771)
    at Object.exportPage [as default] (/Users/saswatamukherjee/web/vantures/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 (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/require.js:1:384)
    at getPagePath (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/require.js:2:82)
    at requirePage (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/require.js:2:227)
    at loadComponents (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/load-components.js:1:771)
    at Object.exportPage [as default] (/Users/saswatamukherjee/web/vantures/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 (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/require.js:1:384)
    at getPagePath (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/require.js:2:82)
    at requirePage (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/require.js:2:227)
    at loadComponents (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/next-server/server/load-components.js:1:771)
    at Object.exportPage [as default] (/Users/saswatamukherjee/web/vantures/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 (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/export/index.js:24:1103)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async build (/Users/saswatamukherjee/web/vantures/node_modules/next/dist/build/index.js:37:218)
Automatically optimizing pages .npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! next-vanture@0.1.0 build: `next build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the next-vanture@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/saswatamukherjee/.npm/_logs/2020-08-07T04_15_52_727Z-debug.log

But when you visit the routes mentioned in the error and then try to build it succeeds.

> next-vanture@0.1.0 build /Users/saswatamukherjee/web/vantures
> next build

Creating an optimized production build  

Compiled successfully.

Automatically optimizing pages  

Page                              Size     First Load JS
┌ ● /                             3.89 kB        62.9 kB
├   /_app                         0 B              59 kB
├ ○ /404                          3.03 kB          62 kB
├ λ /api/rental/[id]              0 B              59 kB
├ λ /api/rental/new               0 B              59 kB
├ λ /api/results                  0 B              59 kB
├ ● /rental/[id]                  1.42 kB        60.4 kB
├   ├ /rental/10059872
├   ├ /rental/10051164
├   ├ /rental/10082307
├   └ [+2 more paths]
└ ○ /rental/new                   52.6 kB         112 kB
+ First Load JS shared by all     59 kB
  ├ chunks/commons.5f7a56.js      10.2 kB
  ├ chunks/framework.1beee9.js    40.6 kB
  ├ chunks/main.cbe33c.js         6.73 kB
  ├ chunks/pages/_app.c4b3a7.js   280 B
  ├ chunks/webpack.f300b4.js      1.19 kB
  └ css/52b58017dc61730a05c9.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
AlexRAV commented 4 years ago

The source of this issue is wrong pages-manifest.json generation for build command while dev working. I'll try to fix it but not sure if I have enough time, so I decided leave this message here, maybe it'll be usefull.

Manifest for build while dev running: image

Manifest for build without dev in background: image

AlexRAV commented 4 years ago

https://github.com/AlexRAV/next.js/blob/fb81ecb2bd85167d2676983a2489e29ea42b6b97/packages/next/next-server/server/require.ts#L42 an error generating at this line

saswatamcode commented 4 years ago

Any idea on how one would go about fixing this?

AlexRAV commented 4 years ago

pages-mainfest-plugin for webpack rewrites this manifest. I suppose that when we rewrite manifest by build command, dev watcher initiating own rebuild process and rewrites manifest again. In theory we could just exclude this manifest file for webpack dev watcher, but I think that's a wrong decision because of build command could change another files and watcher will intiate rebuild anyway. Even if build does not changes any other files right now, it could in the future and this issue will appears again.

saswatamcode commented 4 years ago

I see. Excluding the manifest file would be wrong.

itsclarke commented 4 years ago

@AlexRAV How would you recommend I go about continuing? I need to keep dev running in order for the api calls to fire when building, but it seems that's creating its own issue.

jscardona12 commented 3 years ago

Hi!, I'm having the same problem, did you find a way to solve it?

Oxicode commented 3 years ago

me too, please helpme

touqeeraslam commented 3 years ago

any update on this issue, please?

itsclarke commented 3 years ago

@touqeeraslam I haven't been able to solve it. Ended up not using NextJS because the contributors never got back to me.

gusilveiramp commented 3 years ago

Same problem with deploying to S3 using Github Actions

chankruze commented 3 years ago

I don't understand what's the point of prerendering even before site is deployed. This issue is insane ;(

Edit: For me it was because i had 2 components required by a particular page inside the /pages/<page_name> folder. I just moved them to components folder (/components) where / is project root. And the error got resolved. Further i changed static generation to server side rendering (because it was need to render page on request earlier only 26 pages were built and it was fully static website, gave 404 to other items)

vihapr commented 3 years ago

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 ?

Immortal000 commented 3 years ago

Same error. Any updates?

karthik-js commented 3 years ago

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

rubenscorrea20 commented 3 years ago

Same problem here, any update on this issue, please?

deniercounter commented 3 years ago

+1: info - Generating static pages (9/9)

Build error occurred Error: Cannot find module for page: /account/login at pageNotFoundError (/data/Github/nextjs-with-jest-typescript/node_modules/next/dist/server/require.js:15:17) at Object.getPagePath (/data/Github/nextjs-with-jest-typescript/node_modules/next/dist/server/require.js:38:15) at /data/Github/nextjs-with-jest-typescript/node_modules/next/dist/build/index.js:759:56 at runMicrotasks () at processTicksAndRejections (internal/process/task_queues.js:93:5) at async Span.traceAsyncFn (/data/Github/nextjs-with-jest-typescript/node_modules/next/dist/telemetry/trace/trace.js:60:20) at async /data/Github/nextjs-with-jest-typescript/node_modules/next/dist/build/index.js:630:13 at async Span.traceAsyncFn (/data/Github/nextjs-with-jest-typescript/node_modules/next/dist/telemetry/trace/trace.js:60:20) { code: 'ENOENT' }

codeGTI commented 3 years ago

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.

Aiglobelam commented 2 years ago

I have not tested the repo itsclarke initially reported, and I do not run the commands at the same time... So this is not actually the exact same thing...

But I ended up here in this issue, because I had the problem that the next build command failed with that it could not find some components... But when running next dev locally on my computer it works great.

My problem was a miss match in capital vs non capital in the path name to imported files/components.

I had locally renamed the folders to small caps but git had not recognised this change and not pushed to main repo..

I solve this by using git mv command to make git notice the change in the path naming. I guess the same will work for renaming specific files.

In my case I had a subfolder under components that was named Pollers with a capital P, locally I had renamed it to "pollers".

1: git mv src/components/Pollers src/components/temp 2: git commit -m'... step 1' 3: git mv src/components/temp src/components/pollers 4: git commit -m'... step 2'

Then make sure the import paths use the same path name =)

aliazimoshan commented 2 years ago

Hello All,

I was stocked on this issue for a few days. I solved this problem by removing the unnecessary pages stored in the pages folder in the project. I get this error log,

> Build error occurred Error: Export encountered errors on following paths: 
/en/classic 
/fa/classic

the problem was with classic.tsx file which was in the pages folder. create another folder like non-pages.

>src
  >pages
  >non-pages // I create this folder

at last, I move classic.tsx file to the non-pages folder hope it helps.