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?
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.
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.
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.
--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.
"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"
}
From TypeScript issue #33809:
It really doesn't make sense to have
incremental
andnoEmit
together, sincenoEmit
prevents us from writing incremental metadata. (So nothing is actually incremental).You should consider
emitDeclarationOnly
instead ofnoEmit
, 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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With