选项“baseUrl”已被弃用,将在TypeScript 7中不再起作用
我最近发现我在我的 tsconfig.json 中遇到了以下错误:
Option 'baseUrl' 已被弃用,在TypeScript 7.0中将不再起作用。
请指定编译选项 '"ignoreDeprecations": "6.0"' 以消除此错误。
我该如何修复这个错误?以下是我的tsconfig.json,我用它来在使用TypeScript和 shadcn/ui的 Next.js项目中运行。
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
".next/dev/types/**/*.ts"
],
"exclude": ["node_modules"]
}
解决方案
baseUrl 将不再在TypeScript 7.0中受支持,具体请参考Daniel Rosenwasser在此 相关的GitHub帖子 中的说明。
为了解决该错误,请在你的路径映射中显式包含完整路径。例如,不要使用以下内容
// old file with baseUrl
{
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"@app/*": ["app/*"],
"@lib/*": ["lib/*"]
}
}
}
请删除 baseUrl,路径应该变为:
"paths": {
// add ./src from baseUrl
"@app/*": ["./src/app/*"],
"@lib/*": ["./src/lib/*"]
}
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。