编译VSCode扩展时,typescript持续抱怨error TS2307: Cannot find module 'vscode'
。安装“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)
如何进行?
答案 0 :(得分:4)
运行npm install
将解决此问题。
因为有一个“安装后”脚本(node ./node_modules/vscode/bin/install
),可根据您在项目中使用的引擎来获取 vscode.d.ts 。
检测到的VS Code引擎版本:^ 1.6.0 找到符合引擎范围的最低版本:1.6.0 从以下位置获取vscode.d.ts:https://raw.githubusercontent.com/Microsoft/vscode/e52fb0bc87e6f5c8f144e172639891d8d8c9aa55/src/vs/vscode.d.ts vscode.d.ts已成功安装!
答案 1 :(得分:1)
解决方案是指向vscode.d.ts
目录中的node_modules
的链接。
ln -s /home/work/mymodule/node_modules/vscode.d.ts /usr/share/code/resources/app/out/vs/vscode.d.ts
答案 2 :(得分:0)
将您的Package.json
"scripts"
部分更新为:
"compile": "tsc -watch -p ./",
答案 3 :(得分:0)
就我而言,原因是:无法在 Windows 上加载具有长路径的模块。 相关问题链接:https://github.com/nodejs/node/issues/1990
所以,在我将 nodejs v14.x 升级到 v15.x 之后,问题就消失了。
答案 4 :(得分:-1)
您可以简单地通过yarn install
或npm install
安装它们。如果您在VSCode中遇到“ Visual Studio Code无法监视此大工作区中文件的更改”错误,请按照this链接中的说明进行操作。