我正在使用 Typescript (4.1.3),并开始在 tsconfig.json 中使用自定义路径。从那以后,当我导入任何 .ts 文件时,如果我不使用整个路径,我就会收到错误消息:
错误:(138, 33) TS2307: 找不到模块 'pages/foo/bar' 或其对应的类型声明。
为了解决这个问题,我必须添加前缀'src/',所以我得到'src/pages/foo/bar'。项目本身运行良好,即使出现此 TS 错误。
这是我的 tsconfig.json 文件
{
"compilerOptions": {
"allowJs": true,
"sourceMap": true,
"target": "es6",
"strict": true,
"declaration": false,
"noImplicitAny": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"module": "esnext",
"moduleResolution": "node",
"strictNullChecks": false,
"baseUrl": ".",
"paths": {
"foo": [
"bar.js"
]
},
"types": [
"quasar",
"node",
"cypress"
],
"lib": [
"es2018",
"dom"
]
},
"exclude": [
"node_modules"
],
"extends": "@quasar/app/tsconfig-preset"
}