【发布时间】:2021-05-03 16:35:55
【问题描述】:
我正在使用 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"
}
【问题讨论】:
标签: typescript