I tried to upload a Node.js and Next.js app on Heroku, but it failed because I did not add "type": "module" inside the package.json
After I added "type": "module" to package.json I needed to change the file extension from next.config.js (.js) to next.config.cjs (.cjs (commonJS)). Then I tried to run the app to see if everything works and I got the above error.
It seems that I messed up something with the node.js and the Nextjs environment…
I made some research and I found this discussion on Next JS Github about the issue I am facing. I tried some of these option but I couldn´t solve the error.
Actually I miss the understanding whats going on under the hood, but maybe someone else can understand it and know a possible solution for this.
I think this error message shows up because _document.js is linked to next.config.js and it can not find next.config.cjs. When I delete next.config.cjs I get the same error.
I console.log(Document) inside the console and I get back this:
@oAnfibio I split the project in frontend files and backend files and I decided to host the frontend application on Vercel and the backend application on Heroku, then the error no longer appeared. Actually I am not sure if this is neccessary or if there is any another solution to host both frameworks (Next.js and Node.js) within one project and on one hosting platform.