Arya Anish
Arya Anish

Reputation: 670

Nextjs - importing next/document outside of pages/_document error

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

Upvotes: 21

Views: 19978

Answers (2)

Nikola
Nikola

Reputation: 1011

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

Upvotes: 31

Ryan Le
Ryan Le

Reputation: 8422

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

Upvotes: 12

Related Questions