question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error occurred prerendering page. Cannot read property of undefined.

See original GitHub issue

Bug report

Describe the bug

Build error occured when run next build with dynamic path routing. Error code as below:

Automatically optimizing pages .
Error occurred prerendering page "/posts/[id]". Read more: https://err.sh/next.js/prerender-error:
TypeError: Cannot read property 'map' of undefined

> Build error occurred
Error: Export encountered errors
    at _default (D:\Workspace\nextJsTest\node_modules\next\dist\export\index.js:19:1086)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async build (D:\Workspace\nextJsTest\node_modules\next\dist\build\index.js:36:218)
Automatically optimizing pages .npm ERR! code ELIFECYCLE

To Reproduce

Github repo here

  1. Clone or download github repo.
  2. Run npm install
  3. Run npm run build

Expected behavior

No issue when execute npm run dev. It only happen when execute npm run build. Expected no error occur.

System information

  • OS: Windows
  • Browser Firefox
  • Version of Next.js: 9.3.5
  • Version of Node.js: 12.16.2

Additional context

$ npm run build

nextjstest@1.0.0 build D:\Workspace\nextJsTest next build

Creating an optimized production build

Compiled successfully.

Automatically optimizing pages .
Error occurred prerendering page "/posts/[id]". Read more: https://err.sh/next.js/prerender-error:
TypeError: Cannot read property 'map' of undefined

> Build error occurred
Error: Export encountered errors
    at _default (D:\Workspace\nextJsTest\node_modules\next\dist\export\index.js:19:1086)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async build (D:\Workspace\nextJsTest\node_modules\next\dist\build\index.js:36:218)
Automatically optimizing pages .npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nextjstest@1.0.0 build: `next build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the nextjstest@1.0.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\User\AppData\Roaming\npm-cache\_logs\2020-04-19T05_52_20_084Z-debug.log

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
raychuahcommented, Apr 19, 2020

Thanks!

0reactions
balazsorban44commented, Jan 30, 2022

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

nextjs complains about read property of undefined during build
env Creating an optimized production build Compiled successfully. Automatically optimizing pages . Error occurred prerendering page "/community/ ...
Read more >
Error occurred prerendering page, undefined import file's ...
js app on vercel and I am getting an error (prerender-error) at build time. locale is gotten from useRouter and passed into lang...
Read more >
build export encountered error in NextJS - YouTube
Error occurred prerendering page | build export encountered error in NextJS ... Join this channel to get access to perks: ...
Read more >
typeerror: cannot read properties of undefined ... - You.com
Error occurred prerendering page "/components/movie". Read more: https://nextjs.org/docs/messages/prerender-error TypeError: Cannot read properties of ...
Read more >
NextJS application build error with multiple [slug].js files
The applications contain 4 slug templates in a different path of /pages f… ... Cannot read properties of undefined (reading 'map') Unhandled error...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found