Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
callumok2004 opened this issue Sep 11, 2021 · 10 comments
Labels
bug Issue was opened via the bug report template.

Comments

@callumok2004
Copy link

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

@callumok2004 callumok2004 added the bug Issue was opened via the bug report template. label Sep 11, 2021
@nbouvrette
Copy link
Contributor

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

@junbach
Copy link

junbach commented Sep 13, 2021

I got exactly same issue

@gabor-at-reed
Copy link

Same here

@andrei9669
Copy link

andrei9669 commented Sep 14, 2021

#28596

@housseindjirdeh
Copy link
Collaborator

housseindjirdeh commented 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.

@daliudzius
Copy link

Same issue, I have pages/_document.js under the alternative setup of src/pages/_document.js -- maybe this is the reason for my false positive error.

@housseindjirdeh
Copy link
Collaborator

@daliudzius What version of eslint-config-next or @next/eslint-plugin-next are you using?

@daliudzius
Copy link

@housseindjirdeh My eslint-config-next is on 11.1.2

@ijjk
Copy link
Member

ijjk commented Sep 18, 2021

Closing as a duplicate of #28596 @daliudzius the fix is in 11.1.3-canary.7 please update to at least that version to resolve this.

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

9 participants