Volta: WebStorm does not recognize volta's npm and yarn commands

Created on 3 May 2020  Â·  12Comments  Â·  Source: volta-cli/volta

I tried to get WebStorm (or rather, PhpStorm, but probably WebStorm is the same) to use the npm and yarn commands in ~/.volta/bin, but they are not recognized. node itself _is_ recognized though.

Most helpful comment

Note: The Node image directory has changed slightly since this issue was opened. The npm directory can now be found at:

~/.volta/tools/image/node/<node version>/lib/node_modules/npm (Linux & MacOS)
%LOCALAPPDATA%\Volta\tools\image\node\<node_version>\node_modules\npm (Windows)

All 12 comments

right. webstorm can't follow symlinks. having the same issue

That isn't quite the problem, because node is also a symlink there, but is recognized.

Finally found Webstorms tracking issue: https://youtrack.jetbrains.com/issue/WEB-44867

Interesting, looking at the issue and what you're saying about node working, but npm and yarn not working, my _guess_ is that WebStorm / PhpStorm / IDEA are internally calling something like this:

/path/to/node /path/to/npm

Which then fails to run because it's expecting npm to be a JS file, and the npm that Volta provides on the PATH is a binary. That would align with the comments in the issue about needing to point at the package, not at the binary.

@amcsi In that issue, you commented that nvm points to a shell script, while Volta points at a JS file. Can you explain how you determined that? Running volta which npm for me shows the path to the same shell script (.../bin/npm), not the path to the JS file. Is it possible that those are reversed, and nvm is actually showing the JS file (which would then work correctly with the above command passing it to Node)?

IDE Support is definitely something we'd like to improve on, so figuring out a way to "reveal" the underlying system for use cases like this (beyond what we currently do with volta which) would likely help for more than just the IntelliJ IDEs.

@charlespierce the more underlying npm commands can be found in
~/.volta/tools/image/node/<nodeVersion>/<npmVersion>/bin/npm.

@amcsi Can you clarify a bit? That's the output of volta which npm, but in the linked WebStorm issue, you said that Volta is pointing to npm-cli.js, which is a sibling file to the npm shell script, but I don't believe we directly reference that anywhere.

@charlespierce that that path is a symlink to the npm js:

attila-Predator :: /var/www/lycee-overture ‹master› % ls -al ~/.volta/tools/image/node/11.3.0/6.4.1/bin/npm                                                                                                                            
lrwxrwxrwx 1 attila attila 38 szept  3  2019 /home/attila/.volta/tools/image/node/11.3.0/6.4.1/bin/npm -> ../lib/node_modules/npm/bin/npm-cli.js

I probably miscommunicated. I didn't mean to say that ~/.volta/bin/npm directly linked to to the tools folder; it's pointing to the shim. I was just trying to take it one step at a time and try to see how Webstorm deals with trying to load npm with what the shim (can) point to.

Do these make sense?

Aha, I missed that, thanks! That entire directory (inside of tools/image/node/<node version>/<npm version>/) is the contents of the npm tarball, directly from nodejs.org.

What's interesting is that if WebStorm is running node /path/to/npm to execute npm, it should work using that symlink, because it links to the JS file. On the other hand, if it's executing the command directly, then using the Volta shim binaries in ~/.volta/bin should work. The fact that it doesn't work with either case is extra confusing.

@charlespierce I checked, and what I _was_ able to get Webstorm to recognize was: ./volta/tools/image/node/<node version>/<npm version>/lib/node_modules/npm.

So it could really just be that Webstorm doesn't recognize the js npm executables as npm. I even tried loading nvm's <versionFolder>/bin/npm, and Webstorm didn't recognize that.

This is already great news, because this means that I can manually use individual versions of volta's npm in Webstorm.

Perhaps the shim itself (so just ~/.volta/bin/npm is not working, because under the hood it's pointing to the js npm executable in node's bin/npm rather than node's lib/node_modules/npm/bin/npm.

@amcsi @charlespierce

I was also able to get webstorm to recognize ./volta/tools/image/node/<node version>/<npm version>/lib/node_modules/npm as the npm executable. This is great! I prefer volta and can now use it without anymore trouble with my favorite IDE. Thanks for this :)

EDIT:

Some more great news:

doing ./volta/tools/image/yarn/<yarn version> also allows webstorm to recognize the yarn executable :D

Note: The Node image directory has changed slightly since this issue was opened. The npm directory can now be found at:

~/.volta/tools/image/node/<node version>/lib/node_modules/npm (Linux & MacOS)
%LOCALAPPDATA%\Volta\tools\image\node\<node_version>\node_modules\npm (Windows)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Stanzilla picture Stanzilla  Â·  3Comments

chriskrycho picture chriskrycho  Â·  4Comments

chriskrycho picture chriskrycho  Â·  5Comments

mikrostew picture mikrostew  Â·  3Comments

ef4 picture ef4  Â·  5Comments