Error: <Html> should not be imported outside of pages/_document. #77262
Replies: 10 comments
-
A fudge to fix this strangely is to resolve the ENV error which isnt. Updating the script to the below resolves. "build": "NODE_ENV=production next build" How to actually fix this issue? |
Beta Was this translation helpful? Give feedback.
-
Is this not a bug? Seems like quite a few encounter this, and not resolved. |
Beta Was this translation helpful? Give feedback.
-
Same here, any update please? |
Beta Was this translation helpful? Give feedback.
-
Ah nvm, I misread, ENV for NODE_ENV... strange issue 🤔 EDITCan you echo, NODE_ENV? I wonder if its set in your environment, like globally and such? |
Beta Was this translation helpful? Give feedback.
-
I have the same issue!!!! does this is a BIG BUG??? |
Beta Was this translation helpful? Give feedback.
-
I'm also seeing this issue. The NODE_ENV=production fixed it for me as well. |
Beta Was this translation helpful? Give feedback.
-
In fairness I did notice this, after using the solution from @chrisphillers
|
Beta Was this translation helpful? Give feedback.
-
In my case I had the NODE_ENV set in the Windows variables, after removing it I could build with |
Beta Was this translation helpful? Give feedback.
-
Same issue on local and on Vercel. Did try with/out Debugging:
|
Beta Was this translation helpful? Give feedback.
-
Same here -- this error appeared to crop up out of nowhere. I have no pages/ or Html or next/document called in my repo but yesterday this error popped up on build. Switching NODE_ENV to production worked, but that doesn't undermine the usefulness of having the development environment. I don't know how the server/chunks business works, but something seems to be going on there. I tried newer versions on next (i'm on 15.4.4) and moving to @latest didn't help. My error matches other people's:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Link to the code that reproduces this issue
https://github.com/chrisphillers/yuzzi-film-simple
To Reproduce
Create-next-app is broken.
npx create-next-app@latest whatevernameyouwant
Enter the generated folder
npm i
npm run build
Current vs. Expected behavior
Expected result: build should complete
Actual result:
$ npm run build
⚠ You are using a non-standard "NODE_ENV" value in your environment. This creates inconsistencies in the project and is strongly advised against. Read more: https://nextjs.org/docs/messages/non-standard-node-env
▲ Next.js 15.2.3
Creating an optimized production build ...
✓ Compiled successfully
✓ Linting and checking validity of types
✓ Collecting page data
Error: should not be imported outside of pages/_document.
Read more: https://nextjs.org/docs/messages/no-document-import-in-page
at y (.next/server/chunks/548.js:6:1351)
Error occurred prerendering page "/404". Read more: https://nextjs.org/docs/messages/prerender-error
Error: should not be imported outside of pages/_document.
Read more: https://nextjs.org/docs/messages/no-document-import-in-page
at K (/home/chrisphillers/yuzzi-film-simple/frontend/node_modules/next/dist/compiled/next-server/pages.runtime.prod.js:16:6526)
at y (/home/chrisphillers/yuzzi-film-simple/frontend/.next/server/chunks/548.js:6:1351)
at react-stack-bottom-frame (/home/chrisphillers/yuzzi-film-simple/frontend/node_modules/react-dom/cjs/react-dom-server.edge.development.js:8798:18)
at renderWithHooks (/home/chrisphillers/yuzzi-film-simple/frontend/node_modules/react-dom/cjs/react-dom-server.edge.development.js:4722:19)
at renderElement (/home/chrisphillers/yuzzi-film-simple/frontend/node_modules/react-dom/cjs/react-dom-server.edge.development.js:5157:23)
at retryNode (/home/chrisphillers/yuzzi-film-simple/frontend/node_modules/react-dom/cjs/react-dom-server.edge.development.js:5805:22)
at renderNodeDestructive (/home/chrisphillers/yuzzi-film-simple/frontend/node_modules/react-dom/cjs/react-dom-server.edge.development.js:5631:11)
at renderElement (/home/chrisphillers/yuzzi-film-simple/frontend/node_modules/react-dom/cjs/react-dom-server.edge.development.js:5143:11)
at retryNode (/home/chrisphillers/yuzzi-film-simple/frontend/node_modules/react-dom/cjs/react-dom-server.edge.development.js:5805:22)
at renderNodeDestructive (/home/chrisphillers/yuzzi-film-simple/frontend/node_modules/react-dom/cjs/react-dom-server.edge.development.js:5631:11)
Export encountered an error on /_error: /404, exiting the build.
⨯ Next.js build worker exited with code: 1 and signal: null
Provide environment information
Operating System: Platform: linux Arch: x64 Version: #1 SMP Tue Nov 5 00:21:55 UTC 2024 Available memory (MB): 32061 Available CPU cores: 16 Binaries: Node: 22.14.0 npm: 10.9.2 Yarn: N/A pnpm: N/A Relevant Packages: next: 15.2.3 // Latest available version is detected (15.2.3). eslint-config-next: 15.2.3 react: 19.0.0 react-dom: 19.0.0 typescript: 5.8.2 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
create-next-app
Which stage(s) are affected? (Select all that apply)
next build (local)
Additional context
I am not using an env in the project so no idea why I am getting the ENV warning.
However the Html error I am getting appears to be the showstopper.
I have tried multiple fresh installs and creating a seperate "not found" component to override the standard 404, no no effect.
There was an existing issue ticket for this but for some reason it was closed?
Beta Was this translation helpful? Give feedback.
All reactions