选项“noEmit”不能与选项“incremental”一起指定

2024-02-05

我正在开发一个 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自动注入'noEmit:真' in tsconfig.json文件。虽然我确实需要增量模式来加快构建速度。有什么办法可以解决这个问题呢?


TS 4.0+

--incremental with --noEmit 是可能的 https://devblogs.microsoft.com/typescript/announcing-typescript-4-0-beta/#noemit-and-incremental now:

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

构建信息文件被发射 https://github.com/microsoft/TypeScript/pull/39122即使noEmit。您可以通过设置其显式位置--tsBuildInfoFile https://www.typescriptlang.org/docs/handbook/compiler-options.html。否则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"
  }

更多信息

  • 在 3.7 中允许 noEmit 和合成在一起 #33809 https://github.com/microsoft/TypeScript/issues/33809
  • 启用 noEmit 标志时应创建 .tsbuildinfo 文件 #30661 https://github.com/microsoft/TypeScript/issues/30661
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

选项“noEmit”不能与选项“incremental”一起指定 的相关文章

随机推荐