question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get an error saying cannot import next/document outside of _document even though it is in _document

See original GitHub issue

What 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:closed
  • Created 2 years ago
  • Reactions:15
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
nbouvrettecommented, Sep 11, 2021

I was about to open this issue - got the same problem 😃

2reactions
housseindjirdehcommented, Sep 14, 2021

This is likely related to #28596. Is eslint-config-next (or @next/eslint-plugin-next) installed with version 11.1.3-canary.7 or later? If not, upgrading it and then clearing the cache (next lint --no-cache) should fix this issue.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found