Upon upgrading Next.js from version 10 to 11, I encountered an error while running npm run build
:
Module parse failed: Cannot read property 'forEach' of undefined
File was processed with these loaders: * ./node_modules/next/dist/build/babel/loader/index.js
You may need an additional loader to handle the result of these loaders.
TypeError: Cannot read property 'forEach' of undefined>
Build error occurredError: > Build failed because of webpack errors
It appears that the issue is related to using the spread operator, as removing all instances of it allows the build to succeed.
I came across some similar problems, although they were not specifically related to Next.js 11: