我正在使用Visual Studio Code扩展,我在typescript中使用非相对导入,例如:
import ModuleA from 'modules/ModuleA';
ModuleA
的实际文件夹为src/modules/ModuleA
且tsconfig.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"
]
}
所有内容编译和构建都很好,但是,当我尝试启动扩展以进行测试时,我收到错误:Activating extension failed: Cannot find module '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扩展?
答案 0 :(得分:0)
我有类似的经历,我重新安装了相同版本的节点,并且问题已解决。
我正在使用Mac,所以:
sudo rm -rf /usr/local/lib/node_modules/npm
brew reinstall node
参考:Error: Cannot find module '../lib/utils/unsupported.js' while using Ionic