typescript - Alternativet 'noEmit' kan inte anges tillsammans med alternativet 'incremental'
Jag utvecklar en next.js-app. Den har följande 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"
]
}
Det körs bra i utvecklingsläge men när man skapar en build visas följande fel:
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 injicerar automatiskt 'noEmit: true' i tsconfig.json-filen. Samtidigt behöver jag verkligen det inkrementella läget för snabbare byggnader. Vad kan vara lösningen på detta?
Svar #1
TS 4.0+
--incremental med --noEmit är nu möjligt:
"compilerOptions": {
"noEmit": true,
"incremental": true,
// "tsBuildInfoFile": "/tmp/my-proj/tsbuildinfo" // custom build info file path
// ...
}
Bygg informationsfilen skapas även med noEmit. Du kan ange dess explicita plats via --tsBuildInfoFile. Annars tas outDir - om den fortfarande är inställd - eller tsconfig.json projektrot som utsläppskatalog.
Äldre versioner (tillfällig lösning)
"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"
}
Mer information
- Tillåt noEmit och composite tillsammans i 3.7 #33809
- Filen .tsbuildinfo bör skapas när flaggan noEmit är aktiverad #30661
Svar #2
Från TypeScript-ärende #33809:
Det är verkligen inte vettigt att ha
incrementalochnoEmittillsammans, eftersomnoEmitförhindrar oss från att skriva inkrementell metadata. (Så egentligen är ingenting inkrementellt).Du bör överväga
emitDeclarationOnlyistället förnoEmit, om du faktiskt bara vill ha inkrementell kontroll.
Enligt detta har flaggan incremental: true inte gjort något för att påskynda bygget medan noEmit: true är definierad. Så du bör antingen ta bort noEmit: true eller ändra den till emitDeclarationOnly: true.
Du kan kontrollera utdata-mapparna med outDir och declarationDir.
