I keep getting this error when running npm run dev
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
This error happened while generating the page. Any console logs will be displayed in the terminal window.
However, when I do npm run build
and then npm run start
the site loads fine. It is just on the dev server that it gives that error. The site also deploys to Vercel fine without any issues.
Any idea why I am getting this on the dev server and not production?
Also, I tried deleting the .next
folder, also deleted node_modules
, and installed all packages again, still gives an error. Deployed to different Vercel sites and all of them were fine.
Here is the full error:
Server Error
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
This error happened while generating the page. Any console logs will be displayed in the terminal window.
Call Stack
ReactDOMServerRenderer.render
[project]/node_modules/react-dom/cjs/react-dom-server.node.development.js (4053:17)
ReactDOMServerRenderer.read
[project]/node_modules/react-dom/cjs/react-dom-server.node.development.js (3690:29)
Object.renderToString
[project]/node_modules/react-dom/cjs/react-dom-server.node.development.js (4298:27)
Object.renderPage
[project]/node_modules/next/dist/server/render.js (596:45)
Function.getInitialProps
node_modules/next/dist/pages/_document.js (150:43)
Object.loadGetInitialProps
[project]/node_modules/next/dist/shared/lib/utils.js (69:29)
renderDocument
[project]/node_modules/next/dist/server/render.js (609:48)
Object.renderToHTML
[project]/node_modules/next/dist/server/render.js (647:34)
runMicrotasks
<anonymous>
processTicksAndRejections
internal/process/task_queues.js (97:5)