首页 > 解决方案 > Nextjs - 在 pages/_document 之外导入下一个/文档错误

问题描述

由于 Next.js 自定义文档,我在构建期间收到此错误。

因此,在构建期间,我收到一条错误消息,说我也有_document.jsin 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.

在此处输入图像描述

请帮我!

编辑

将 next 和 eslint-config-next 更新到版本 11.1.3-canary.7

标签: node.jscompiler-errorsnext.js

解决方案


已在#28596中修复的已知问题

如果您不想更新到金丝雀版本并仍继续正常工作,只需将其从您的.eslintrc.json规则中排除:

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

有关如何在此处排除规则的更多信息:禁用规则


推荐阅读