【问题标题】:How to disable typescript for failing my builds with nextjs?如何禁用打字稿以使我的 nextjs 构建失败?
【发布时间】:2021-08-21 00:04:51
【问题描述】:

运行yarn next build时出现一堆类型错误,例如:

Type error: Property 'href' does not exist on type '{ name: string; }'.

这导致我的构建失败。我可以在我的 tsconfig 中输入一个命令来防止这种情况发生吗?

【问题讨论】:

  • 您能确定代码中发生错误的具体行吗?
  • 尝试修复根本原因而不是修复症状。在此处发布相关代码,以便我们提供更具体的解决方案。参考:How to create a Minimal, Reproducible Example
  • 正如官方文档中所说,它应该是next.config.js 选项:typescript: { ignoreBuildErrors: true },但对我来说它实际上不起作用。另一种选择是使用/* eslint-disable */ 消除所有错误(不是警告),然后构建应该可以工作。

标签: javascript reactjs typescript next.js


【解决方案1】:

来自 NextJS 文档:https://nextjs.org/docs/api-reference/next.config.js/ignoring-typescript-errors

只需将此行放在 typescript 部分下的 next.config.js 中:

module.exports = {
  typescript: {
    // !! WARN !!
    // Dangerously allow production builds to successfully complete even if
    // your project has type errors.
    // !! WARN !!
    ignoreBuildErrors: true,
  },
}

【讨论】:

    【解决方案2】:

    随便放

    // @ts-ignore 
    

    在您要禁用类型检查的行中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-23
      • 2021-04-05
      • 1970-01-01
      • 2021-01-02
      • 1970-01-01
      • 1970-01-01
      • 2019-11-14
      • 1970-01-01
      相关资源
      最近更新 更多