Option 'noEmit' cannot be specified with option 'incremental'

后端 未结 2 1810
慢半拍i
慢半拍i 2021-02-19 20:38

I am developing a next.js app. It has the following tsconfig.js

{
  \"compilerOptions\": {
    \"target\": \"ES2018\",
    \"module\": \"esnext\",
          


        
相关标签:
2条回答
  • 2021-02-19 20:41

    From TypeScript issue #33809:

    It really doesn't make sense to have incremental and noEmit together, since noEmit prevents us from writing incremental metadata. (So nothing is actually incremental).

    You should consider emitDeclarationOnly instead of noEmit, if you actually just want incremental checking.

    According to this, the incremental: true flag has done nothing to speed up the build while noEmit: true is defined. So you should either remove noEmit: true or change it to emitDeclarationOnly: true.

    You can control the output folders using outDir and declarationDir.

    0 讨论(0)
  • 2021-02-19 20:48

    TS 4.0+

    --incremental with --noEmit is possible now:

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

    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.

    Older versions (workaround)

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

    More info

    • Allow noEmit and composite together in 3.7 #33809
    • .tsbuildinfo file should be created when the noEmit flag is enabled #30661
    0 讨论(0)
提交回复
热议问题