Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 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?

like image 694
Muhammad Zeeshan Avatar asked Mar 06 '20 12:03

Muhammad Zeeshan


People also ask

What is noEmit?

The noEmit option tells TypeScript that we only want to run type checking and do not want the compiler to output any transpiled code. Once a tsconfig file is present, VSCode (or your favorite IDE) should detect that TypeScript is used and automatically type check your code.

What is incremental Tsconfig?

TypeScript 3.4 introduces a new flag called incremental which tells TypeScript to save information about the project graph from the last compilation. The next time TypeScript is invoked with incremental , it will use that information to detect the least costly way to type-check and emit changes to your project.

What is composite in Tsconfig?

Composite is a structural design pattern that allows composing objects into a tree-like structure and work with the it as if it was a singular object. Composite became a pretty popular solution for the most problems that require building a tree structure.


2 Answers

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
like image 98
ford04 Avatar answered Sep 30 '22 17:09

ford04


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.

like image 33
Sampo Avatar answered Sep 30 '22 17:09

Sampo