选项 'noEmit' 不能用选项 'incremental' 指定 [英] Option 'noEmit' cannot be specified with option 'incremental'

查看:18
本文介绍了选项 'noEmit' 不能用选项 'incremental' 指定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am developing a next.js app. It has the following 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"
  ]
}

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

It is running well in the development mode but while creating build it shows following error:

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'.虽然我真的需要增量模式来加快构建速度.有什么办法可以解决这个问题?

Next.js automatically injects 'noEmit: true' in tsconfig.json file. While i really need the incremental mode for faster builds. What can be the solution to this?

推荐答案

TS 4.0+

--incremental--noEmit 现在可以:

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

生成信息文件 即使使用 noEmit>.您可以通过 --tsBuildInfoFile.否则 outDir - 如果仍然设置 - 或 tsconfig.json 项目根被视为发射目录.

The build info file is emitted even with noEmit. You can set its explicit location via --tsBuildInfoFile. Otherwise outDir - if still set - or tsconfig.json project root is taken as emit directory.

  "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"
  }

更多信息

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆