【问题标题】:Option 'noEmit' cannot be specified with option 'incremental'选项 'noEmit' 不能用选项 'incremental' 指定
【发布时间】:2020-06-19 04:23:29
【问题描述】:

我正在开发一个 next.js 应用程序。它有以下tsconfig.js

{
  "compilerOptions": {
    "target": "ES2018",
    "module": "esnext",
    "lib": [
      "dom",
      "es2018",
      "es2019.array"
    ],
    "jsx": "preserve",
    "sourceMap": true,
    "skipLibCheck": true,
    "strict": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "allowJs": true,
    "forceConsistentCasingInFileNames": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "incremental": true
  },
  "exclude": [
    "server",
    "next.config.js"
  ],
  "include": [
    "lib/global.d.ts",
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx",
    "**/*.js"
  ]
}

它在开发模式下运行良好,但在创建构建时显示以下错误:

ERROR in tsconfig.json
22:5 Option 'noEmit' cannot be specified with option 'incremental'.
    20 |     "resolveJsonModule": true,
    21 |     "isolatedModules": true,
  > 22 |     "noEmit": true,
       |     ^
    23 |     "incremental": true
    24 |   },
    25 |   "exclude": [

Next.js 自动在tsconfig.json 文件中注入'noEmit: true'。虽然我真的需要增量模式来加快构建速度。有什么办法可以解决这个问题?

【问题讨论】:

    标签: typescript webpack babeljs next.js


    【解决方案1】:

    TS 4.0+

    --incremental--noEmit is possible 现在:

    "compilerOptions": {
      "noEmit": true,
      "incremental": true,
      // "tsBuildInfoFile": "/tmp/my-proj/tsbuildinfo" // custom build info file path
      // ...
    }
    

    构建信息文件is emitted,即使是noEmit。您可以通过--tsBuildInfoFile 设置其显式位置。否则 outDir - 如果仍然设置 - 或 tsconfig.json 项目根被视为发射目录。

    旧版本(解决方法)

      "compilerOptions": {
        "incremental": true,
        "declaration": true,
        "emitDeclarationOnly": true, // to emit at least something
        // "noEmit": true,
        // ...
        
        // Either set overall output directory
        "outDir": "dist",
        //  or separate locations for build file and declarations 
        // "declarationDir": "dist"
        // "tsBuildInfoFile": "/tmp/my-proj/tsbuildinfo"
      }
    

    更多信息

    【讨论】:

      【解决方案2】:

      来自TypeScript issue #33809

      incrementalnoEmit 放在一起确实没有意义,因为noEmit 会阻止我们编写增量元数据。 (所以实际上没有什么是增量的)。

      如果您实际上只是想要增量检查,则应该考虑 emitDeclarationOnly 而不是 noEmit

      据此,incremental: true 标志在定义 noEmit: true 时没有做任何事情来加速构建。因此,您应该删除 noEmit: true 或将其更改为 emitDeclarationOnly: true

      您可以使用outDirdeclarationDir 控制输出文件夹。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-06-14
        • 2012-07-09
        • 1970-01-01
        • 2013-04-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多