typescript - vscode 激活扩展失败 : Cannot find module with non-relative import

标签 typescript visual-studio-code vscode-extensions

我正在开发 Visual Studio Code 扩展,我在 typescript 中使用非相对导入,例如:

import ModuleA from 'modules/ModuleA';

ModuleA 的实际文件夹是 src/modules/ModuleAtsconfig.json 如下,我指定 >src 作为 baseUrl:

{
  "compilerOptions": {
    "baseUrl": "./src",
    "module": "commonjs",
    "target": "es6",
    "outDir": "out",
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true,
    "lib": [
      "es6"
    ],
    "sourceMap": true,
    "strictNullChecks": true,
    "experimentalDecorators": true,
    "moduleResolution": "node"
  },
  "exclude": [
    "node_modules",
    ".vscode-test"
  ]
}

一切编译和构建都很好,但是,当我尝试启动扩展进行测试时,我收到错误:激活扩展失败:找不到模块“modules/ModuleA”。我用来启动扩展的 .vscode/launch.json 文件如下所示:

// A launch configuration that compiles the extension and then opens it inside a new window
{
  "version": "0.1.0",
  "configurations": [
    {
      "name": "Launch Extension",
      "type": "extensionHost",
      "request": "launch",
      "runtimeExecutable": "${execPath}",
      "args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
      "stopOnEntry": false,
      "sourceMaps": true,
      "outFiles": ["${workspaceRoot}/out"],
      "preLaunchTask": "build",
      "internalConsoleOptions" : "openOnSessionStart"
  }
  ]
}

如何使用非相对路径来开发 vscode 扩展?

最佳答案

我也有过类似的经历,重装node,同版本,问题解决。

我使用的是 Mac,所以:

sudo rm -rf /usr/local/lib/node_modules/npm
brew reinstall node

引用:Error: Cannot find module '../lib/utils/unsupported.js' while using Ionic

关于typescript - vscode 激活扩展失败 : Cannot find module with non-relative import,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43197245/

相关文章:

Angular Service Worker - Rest API 数据

angular - 传单错误 : Invalid LatLng object: (, NaN)

reactjs - 使 VSCode 将语法高亮应用于 .tsx 文件

python - "Source file found twice"错误,mypy>=0.780 在 python 中用于 vscode

visual-studio-code - 如何从 vscode 扩展写入日志?

visual-studio-code - VSCode 选择片段

javascript - 有没有办法启用 VS Code WebView 的搜索功能?

node.js - 如何修复 : Type 'Window' is not assignable to type 'typeof globalThis'

angular - ng build --prod index.html 文件没有生成后?

visual-studio-code - 搜索(在文件中查找)键绑定(bind)可以带参数,workbench.view.search 不能 - 其他区别?