所以,我正在使用这个 tsconfig.json
:
{
"compilerOptions": {
"baseUrl": ".",
"declaration": true,
"module": "ES6",
"moduleResolution": "node",
"outDir": "./lib/",
"paths": {
"@src/*": ["src/*"]
},
"preserveConstEnums": true,
"removeComments": true,
"sourceMap": true,
"target": "ES6"
},
"include": [
"global.d.ts",
"src/**/*.ts"
]
}
在哪里可以看到别名
@src
是为我的代码定义的。tsc
/webpack
构建所有内容都没有问题,但是在 VS Code 中进行编辑时,当我将某些内容作为import { xxx } from '@src/xxx';
有同样问题的人吗?对我来说,看到这一点很奇怪,因为如果它正确编译/构建(来自 tsc 和 webpack),这意味着配置是正确的。那么为什么 VS Code 会显示这个错误消息呢?这只是烦人,但我想解决它。
tsconfig.json
文件也使用标准名称(-p
没有自定义 tsc
选项)所以,VS Code 应该能够自动读取它,对吧?或者IDE需要任何额外的配置?
最佳答案
我遇到过同样的问题。在我的情况下运行 Cmd+Shift+P > Typescript: Restart TS Server
技巧和错误信息是否消失了
关于typescript - 在 VS 代码 : [ts] Cannot find module '@src/xxx' 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51319613/