【问题标题】:Nextjs - importing next/document outside of pages/_document errorNextjs - 在 pages/_document 之外导入下一个/文档错误
【发布时间】:2021-11-02 18:12:12
【问题描述】:

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

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

【问题讨论】:

  • 如果您看到next/document 躺在其他地方,请四处搜索?
  • 不,没有
  • 这是一个已知问题,请尝试更新为我的答案,看看是否有帮助。

标签: node.js compiler-errors next.js


【解决方案1】:

#28596 中修复的已知问题

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

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

有关如何在此处排除规则的更多信息:disabling-rules

【讨论】:

  • 谢谢,这个解决方案解决了我的问题
【解决方案2】:

这是来自最新 Nextjs 更新的known issue

Nextjs 团队引述:

这已在 #28745 中修复,并在 11.1.3-canary.7 中有效。如果您遇到此问题并且仍然看到相同的错误,请升级到该版本,请确保清除您的缓存(下一个 lint --no-cache)。


结论:

您需要将Nextjseslint-config-next 更新为11.1.3-canary.7,并且不要忘记清除缓存next lint --no-cache

【讨论】:

  • 怎么回事?你更新到那个版本并清除缓存了吗?
  • 好的,我再试一次
  • 好的,如果有帮助请告诉我。
  • 对不起,我来晚了。刚刚将next and eslint-config-next 更改为版本11.1.3-canary.7
猜你喜欢
  • 2019-02-10
  • 2023-02-13
  • 1970-01-01
  • 2022-10-17
  • 2021-10-03
  • 2022-08-14
  • 2017-08-03
  • 2020-03-16
  • 2021-02-20
相关资源
最近更新 更多