close

[Solved] next/document should not be imported outside of pages/_document.js

Hello Guys, How are you all? Hope You all Are Fine. Today I am facing following error next/document should not be imported outside of pages/_document.js in next.js. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How next/document should not be imported outside of pages/_document.js Error Occurs ?

I am facing following error while build next.js.

next/document should not be imported outside of pages/_document.js. See https://nextjs.org/docs/messages/no-document-import-in-page.

How To Solve next/document should not be imported outside of pages/_document.js Error ?

  1. How To Solve next/document should not be imported outside of pages/_document.js Error?

    To Solve next/document should not be imported outside of pages/_document.js Error You just need to update Nextjs and eslint-config-next to 11.1.3-canary.7 to solve this error and then just clear cache with next lint --no-cache second solution is If You dont want to update nextjs then simply you have to exclude document from your .eslintrc.json.

  2. next/document should not be imported outside of pages/_document.js

    To Solve next/document should not be imported outside of pages/_document.js Error You just need to update Nextjs and eslint-config-next to 11.1.3-canary.7 to solve this error and then just clear cache with next lint --no-cache second solution is If You dont want to update nextjs then simply you have to exclude document from your .eslintrc.json.

Solution 1: Update Nextjs and eslint-config-next

You just need to update Nextjs and eslint-config-next to 11.1.3-canary.7 to solve this error and then just clear cache with next lint --no-cache

Solution 2: just exclude document from your .eslintrc.json

If You dont want to update nextjs then simply you have to exclude document from your .eslintrc.json. Here is how.

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

Summary

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Also, Read

Leave a Comment