Muh*_*han 13 typescript webpack babeljs next.js
我正在开发 next.js 应用程序。它有以下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"
]
}
Run Code Online (Sandbox Code Playgroud)
它在开发模式下运行良好,但在创建构建时显示以下错误:
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": [
Run Code Online (Sandbox Code Playgroud)
Next.js自动在文件中注入“noEmit: true”tsconfig.json
。虽然我真的需要增量模式来加快构建速度。有什么办法可以解决这个问题?
--incremental
--noEmit
现在可以:
"compilerOptions": {
"noEmit": true,
"incremental": true,
// "tsBuildInfoFile": "/tmp/my-proj/tsbuildinfo" // custom build info file path
// ...
}
Run Code Online (Sandbox Code Playgroud)
即使使用. noEmit
您可以通过设置其显式位置--tsBuildInfoFile
。否则outDir
- 如果仍然设置 - 或tsconfig.json
项目根目录将被视为发出目录。
"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"
}
Run Code Online (Sandbox Code Playgroud)
incremental
将和放在一起确实没有意义noEmit
,因为noEmit
它会阻止我们编写增量元数据。(所以没有什么实际上是增量的)。如果您实际上只想进行增量检查,则应该考虑
emitDeclarationOnly
而不是。noEmit
据此,该标志在定义incremental: true
时没有采取任何措施来加速构建。noEmit: true
因此,您应该删除noEmit: true
或将其更改为emitDeclarationOnly: true
.
outDir
您可以使用和控制输出文件夹declarationDir
。
归档时间: |
|
查看次数: |
4180 次 |
最近记录: |