Build nest.js by tsconfig.json
对比这两个 tsconfig.json
文件,我们可以看到一些关键的差异。让我们逐项分析一下这些差异,并指出可能存在的问题。
修改前的 tsconfig.json
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"declaration": true,
"outDir": "./dist",
"baseUrl": "./",
"resolveJsonModule": true,
"isolatedModules": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"target": "ES2021",
"module": "commonjs",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false,
"removeComments": true,
"paths": {
"@/*": ["./*"]
}
}
}
修改后的 tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "ES2021",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false
}
}
主要差异
-
缺少的配置:
-
修改后的版本中删除了以下选项:
-
"lib": ["dom", "dom.iterable", "esnext"]
:指定要包含在编译中的库。 -
"allowJs": true
:允许编译JavaScript文件。 -
"noEmit": true
:不生成输出文件。 -
"resolveJsonModule": true
:允许导入JSON模块。 -
"isolatedModules": true
:确保每个文件都是单独的模块。 -
"paths": { "@/*": ["./*"] }
:配置路径别名。
-
-
-
影响
-
编译输出:
"noEmit": true
的删除使得TypeScript编译器不再阻止生成输出文件,这可能是编译后没有输出的原因。确保你真的需要输出文件时,请不要启用noEmit
。 -
JavaScript支持:删除
allowJs
可能会导致编译器忽略任何JavaScript文件。 -
库引用:删除
lib
配置后,TypeScript可能无法识别某些全局类型,如DOM相关类型。 -
模块解析:
resolveJsonModule
和isolatedModules
的删除可能影响你如何处理JSON模块和模块解析。
-
建议
根据需求,调整 tsconfig.json
中的选项。如果你需要输出文件,确保 noEmit
设置为 false
或删除该选项。如果项目中包含JavaScript文件,请启用 allowJs
。
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"strict": true,
"noEmit": false, // 确保生成输出文件
"esModuleInterop": true,
"declaration": true,
"outDir": "./dist",
"baseUrl": "./",
"resolveJsonModule": true,
"isolatedModules": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"target": "ES2021",
"module": "commonjs",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false,
"removeComments": true,
"paths": {
"@/*": ["./*"]
}
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通