npm 错误代码:错误TS2307:找不到模块“vscode”

3mpgtkmj  于 2023-01-09  发布在  Vscode
关注(0)|答案(6)|浏览(301)

编译VSCode扩展时, typescript 持续出现问题
错误TS2307:找不到模块"vcode"。
安装npm install vscode或魔术链接从来没有帮助。
Strace提供:

stat("/home/work/mymodule/src/node_modules", 0x7ffe73f2d460) = -1 ENOENT (No such file or directory)
stat("/home/work/mymodule/node_modules", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
stat("/home/work/mymodule/node_modules/vscode", 0x7ffe73f2d200) = -1 ENOENT (No such file or directory)
stat("/home/work/mymodule/node_modules", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
stat("/home/work/mymodule/node_modules/vscode.ts", 0x7ffe73f2d040) = -1 ENOENT (No such file or directory)
stat("/home/work/mymodule/node_modules/vscode.tsx", 0x7ffe73f2d040) = -1 ENOENT (No such file or directory)
stat("/home/work/mymodule/node_modules/vscode.d.ts", 0x7ffe73f2d040) = -1 ENOENT (No such file or directory)
stat("/home/work/mymodule/node_modules/vscode", 0x7ffe73f2d230) = -1 ENOENT (No such file or directory)
stat("/home/work/mymodule/node_modules/@types", 0x7ffe73f2d460) = -1 ENOENT (No such file or directory)
stat("/home/tma/work/qore/node_modules", 0x7ffe73f2d460) = -1 ENOENT (No such file or directory)
stat("/home/tma/work/node_modules", 0x7ffe73f2d460) = -1 ENOENT (No such file or directory)
stat("/home/tma/node_modules", 0x7ffe73f2d460) = -1 ENOENT (No such file or directory)
stat("/home/node_modules", 0x7ffe73f2d460) = -1 ENOENT (No such file or directory)
stat("/node_modules", 0x7ffe73f2d460)   = -1 ENOENT (No such file or directory)
stat("/home/work/mymodule/src/node_modules", 0x7ffe73f2d460) = -1 ENOENT (No such file or directory)
stat("/home/work/mymodule/node_modules", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
stat("/home/work/mymodule/node_modules/vscode", 0x7ffe73f2d200) = -1 ENOENT (No such file or directory)
stat("/home/work/mymodule/node_modules", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
stat("/home/work/mymodule/node_modules/vscode.js", 0x7ffe73f2d040) = -1 ENOENT (No such file or directory)
stat("/home/work/mymodule/node_modules/vscode.jsx", 0x7ffe73f2d040) = -1 ENOENT (No such file or directory)
stat("/home/work/mymodule/node_modules/vscode", 0x7ffe73f2d230) = -1 ENOENT (No such file or directory)

如何进行?

mfuanj7w

mfuanj7w1#

解决方案

运行npm install以解决此问题。

为什么?

因为有一个"安装后"脚本(node ./node_modules/vscode/bin/install),它根据您在项目中使用的引擎获取vscode. d. ts
检测到的VS代码引擎版本:^1.6.0找到符合引擎范围的最低版本:1.6.0从以下位置获取vscode. d. ts:https://raw.githubusercontent.com/Microsoft/vscode/e52fb0bc87e6f5c8f144e172639891d8d8c9aa55/src/vs/vscode.d.ts vscode. d. ts已成功安装!

xmd2e60i

xmd2e60i2#

解决方案是从node_modules目录指向vscode.d.ts的链接。

ln -s /home/work/mymodule/node_modules/vscode.d.ts /usr/share/code/resources/app/out/vs/vscode.d.ts
e5nszbig

e5nszbig3#

将您的Package.json"scripts"部分更新为:

"compile": "tsc -watch -p ./",
toe95027

toe950274#

就我而言,原因是:无法在Windows上加载具有长路径的模块。相关问题链接:https://github.com/nodejs/node/issues/1990
所以,在我将nodejsv14.x升级到v15.x之后,这个问题就消失了。

t1rydlwq

t1rydlwq5#

如果在尝试为vsCode扩展创建webview时遇到此错误,请检查是否在client文件夹下而不是在server文件夹下执行此操作

zrfyljdw

zrfyljdw6#

我建议您关闭并打开VS Code

相关问题