typescript - 在 VS 代码 : [ts] Cannot find module '@src/xxx' 中

标签 typescript visual-studio-code

所以,我正在使用这个 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/

相关文章:

javascript - 我的 reducer 可以使用 Set 作为初始值吗?

powershell - VSCode - 在单独的窗口中打开终端

python - pytest 无法发现 VSCode 中的测试

javascript - VsCode 不使用单引号格式化 TS/JS 文件

javascript - Web 共享 API 在 iOS : Angular 上不起作用

reactjs - 用泛型 react 上下文

angular - Angular 中的主题在 500 内部错误后停止工作

javascript - 更改客户端编程语言中的键盘语言

visual-studio-code - Visual Studio Code `quick fix`可以与键盘交互吗?

python - 在 Visual Studio Code 中禁用自动换行