Error occurred prerendering page. Cannot read property of undefined.
See original GitHub issueBug 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
- Clone or download github repo.
- Run npm install
- 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:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Thanks!
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.