gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 07:44:01 24 4
gpt4 key购买 nike

我正在开发 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com