[英]VSCode extension cannot find module when installed from Marketplace
I'm trying to write a VS Code Extension that require
s other node modules.我正在尝试编写一个require
其他节点模块的 VS 代码扩展。 Unfortunately the modules are not found when a user installs the extensions from the marketplace.不幸的是,当用户从市场安装扩展时,找不到这些模块。
What I did is add the modules to the dependencies
section of my package.json
(Which is what theextension manifest wants).我所做的是将模块添加到我的package.json
的dependencies
项部分(这是扩展清单想要的)。 When I run npm install
locally, a node_modules
folder is created and contains the modules.当我在本地运行npm install
时,会创建一个node_modules
文件夹并包含模块。 Running the extension locally via launch.json works.通过 launch.json 在本地运行扩展。
However when the extension is installed through the VS Code Marketplace , triggering its action will fail and the debug tools console will show the message但是,当通过VS Code Marketplace安装扩展时,触发其操作将失败,并且调试工具控制台将显示消息
Activating extension 'lalten.vscode-unify' failed: Cannot find module 'tempy'
Require stack:
- /home/laurenz/.vscode-server/extensions/lalten.vscode-unify-0.2.2/out/extension.js
- /home/laurenz/.vscode-server/bin/3c4e3df9e89829dce27b7b5c24508306b151f30d/out/vs/loader.js
- /home/laurenz/.vscode-server/bin/3c4e3df9e89829dce27b7b5c24508306b151f30d/out/bootstrap-amd.js
- /home/laurenz/.vscode-server/bin/3c4e3df9e89829dce27b7b5c24508306b151f30d/out/bootstrap-fork.js.
And the node_modules dir is indeed missing:确实缺少 node_modules 目录:
$ ls /home/user/.vscode-server/extensions/lalten.vscode-unify-0.2.2/
icon.png images LICENSE.md out package.json README.md
(This happens both in a local and ssh-remote vscode-server, /home/laurenz/.vscode/extensions/lalten.vscode-unify-0.2.2/
also has no node_modules.) (这发生在本地和 ssh-remote vscode-server 中,/home/laurenz/.vscode/extensions/lalten.vscode-unify- /home/laurenz/.vscode/extensions/lalten.vscode-unify-0.2.2/
也没有 node_modules。)
The .vscodeignore seems to be innocent and vsce ls
includes node_modules/. .vscodeignore似乎是无辜的,并且vsce ls
包含 node_modules/。
Other people had this problem in the past, but their resolution was to update vsce (I have the most recent 1.87.1), using dependencies instead of devDependencies (which I do), or deleting the node_modules folder (which did not help).其他人过去也遇到过这个问题,但他们的解决方案是更新 vsce (我有最新的 1.87.1),使用依赖项而不是 devDependencies (我这样做),或者删除 node_modules 文件夹(没有帮助)。
I also find it curious that the extension works in CI , so my hunch is that it must be something with how it's published.我也很奇怪这个扩展在CI中工作,所以我的直觉是它必须与它的发布方式有关。
Any ideas?有任何想法吗?
It turns out my package.json had in the scripts
section:原来我的 package.json 在scripts
部分有:
"deploy": "vsce publish --yarn"
when it should have been应该是什么时候
"deploy": "vsce publish"
Now the node_modules
are included.现在包含了node_modules
。
Thanks for the helpful comments that brought me on the right track.感谢那些让我走上正轨的有用评论。 I will also look into bundling the extension in the future.我还将考虑在未来捆绑扩展。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.