问题描述
我正在开发一个 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"
}
更多信息
- 在 3.7 中允许 noEmit 和复合 #33809
- .tsbuildinfo 文件应在启用 noEmit 标志时创建 #30661
这篇关于选项 'noEmit' 不能用选项 'incremental' 指定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!