Get an error saying cannot import next/document outside of _document even though it is in _document
See original GitHub issueWhat version of Next.js are you using?
11.1.2
What version of Node.js are you using?
16.6.1
What browser are you using?
Chrome
What operating system are you using?
Windows
How are you deploying your application?
next start
Describe the Bug
When running next lint
I get the following output.
yarn run v1.22.10
$ next lint --fix
info - Loaded env from E:\Developing\Ansen\Recode\.env
info - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
./src/pages/_document.tsx
1:1 Error: next/document should not be imported outside of pages/_document.js. See https://nextjs.org/docs/messages/no-document-import-in-page. @next/next/no-document-import-in-page
info - Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/basic-features/eslint#disabling-rules
Expected Behavior
It should not be giving the error as the import IS inside _document
To Reproduce
Create a _document.tsx
file in src/pages/
, have an import for next/document
, e.g import Document, { Head, Html, Main, NextScript } from 'next/document';
run next lint
Issue Analytics
- State:
- Created 2 years ago
- Reactions:15
- Comments:10 (3 by maintainers)
Top Results From Across the Web
importing next/document outside of pages/_document error ...
So, during the build time I am getting an error saying, Also I have the _document.js in pages/_document.js . next/document should not be ......
Read more >no-document-import-in-page
Why This Error Occurred. next/document was imported in a page outside of pages/_document.js (or pages/_document.tsx if you are using TypeScript).
Read more >Why am I having issues importing files from cloud storage ...
Open the iPad Settings app, scroll down to each of the LIT SUITE apps, and then change the Document Storage setting to On...
Read more >Dred Scott v. Sandford (1857)
John F. A. Sandford; 3/6/1857; Dred Scott, Plaintiff in Error, v. ... online tool for teaching with documents from the National Archives.
Read more >How to Remove Bad Document from Operation?
The problem is that even though the next document is good, ... but when I click on those files in Documentum, I get...
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 FreeTop 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
Top GitHub Comments
I was about to open this issue - got the same problem 😃
This is likely related to #28596. Is
eslint-config-next
(or@next/eslint-plugin-next
) installed with version11.1.3-canary.7
or later? If not, upgrading it and then clearing the cache (next lint --no-cache
) should fix this issue.