Next.js: Build occasionally fails complains about missing modules but also succeeds

Created on 4 Aug 2020  ยท  15Comments  ยท  Source: vercel/next.js

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

  • OS: macOS
  • Version of Next.js: 9.5.1
  • Version of Node.js: 14.5.0
good first issue bug needs investigation

All 15 comments

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

> [email protected] 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

> [email protected] 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! [email protected] build: `next build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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 [email protected]
3 info using [email protected]
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle [email protected]~prebuild: [email protected]
6 info lifecycle [email protected]~build: [email protected]
7 verbose lifecycle [email protected]~build: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~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 [email protected]~build: CWD: C:\Users\amber\Desktop\opensource_help\vantures
10 silly lifecycle [email protected]~build: Args: [ '/d /s /c', 'next build' ]
11 silly lifecycle [email protected]~build: Returned: code: 1  signal: null
12 info lifecycle [email protected]~build: Failed to exec build script
13 verbose stack Error: [email protected] 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 [email protected]
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 [email protected] build: `next build`
22 error Exit status 1
23 error Failed at the [email protected] 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

  • OS: Microsoft Windows 10 Home Version 10.0.18363 Build 18363
  • node v14.5.0
  • next v9.5.1

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

> [email protected] 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:

> [email protected] 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! [email protected] build: `next build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] 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:

> [email protected] 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! [email protected] build: `next build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] 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:
```

[email protected] 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:

  • OS: macOS Cataline version 10.15.5
  • Node: v12.18.2
  • Next.js: v9.5.1

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

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.

> [email protected] 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! [email protected] build: `next build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] 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.

> [email protected] 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

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

Any idea on how one would go about fixing this?

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.

I see. Excluding the manifest file would be wrong.

@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.

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

me too, please helpme

any update on this issue, please?

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

Same problem with deploying to S3 using Github Actions

Was this page helpful?
0 / 5 - 0 ratings

Related issues

timneutkens picture timneutkens  ยท  72Comments

robinvdvleuten picture robinvdvleuten  ยท  74Comments

baldurh picture baldurh  ยท  74Comments

nickredmark picture nickredmark  ยท  60Comments

timneutkens picture timneutkens  ยท  250Comments