21

I am getting this error during build time because of Next.js custom document.

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 imported outside of pages/_document.js. See https://nextjs.org/docs/messages/no-document-import-in-page.

enter image description here

Please help me!

EDIT

Update next and eslint-config-next to version 11.1.3-canary.7

3
  • 1
    Search around if you see next/document laying somewhere else? Commented Sep 5, 2021 at 7:05
  • No, there's not Commented Sep 5, 2021 at 7:09
  • 1
    This is a known issue, try to update as my answer to see if it helps. Commented Sep 5, 2021 at 7:58

2 Answers 2

31

A known issue that is fixed in #28596

If you don't want to update to the canary versions and still keep working normally just exclude it from your .eslintrc.json rules:

"rules": {
    "@next/next/no-document-import-in-page": "off"
}

More info on how to exclude rules here: disabling-rules

Sign up to request clarification or add additional context in comments.

1 Comment

Still facing this issue on version 13.5.4. Was facing a different issue with import on the latest next 14.1.0 tried to make create an issue on the github repository but turns out codesandbox is not working in itself so I can't share the steps to reproduce. Might have to create an issue for that also. Strange weekend.
12

This is a known issue from the latest Nextjs update

Quote from Nextjs team:

This is fixed in #28745 and works in 11.1.3-canary.7. Please upgrade to that version if you're experiencing this issue and if you're still seeing the same error, make sure to clear your cache (next lint --no-cache).


Conclude:

You need to update Nextjs and eslint-config-next to 11.1.3-canary.7 and don't forget to clear cache next lint --no-cache

4 Comments

How comes? Did you update to that version and clear cache?
Ok, let me try again
Sure, Let me know if it helps.
Srry, I am a bit late. just changed next and eslint-config-next to version 11.1.3-canary.7

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.