简体   繁体   English

如何使用nvm使用不同版本的节点运行npm命令?

[英]How do I run an npm command with a different version of node using nvm?

Tried these: 试过这些:

✗ nvm run 9 npm start 
Running node v9.10.1 (npm v5.8.0)
module.js:545
    throw err;
    ^

Error: Cannot find module '/Users/foo/work/grid-styled/npm'
    at Function.Module._resolveFilename (module.js:543:15)



✗ nvm run 9 npm -- x0 dev docs/App.js
Running node v9.10.1 (npm v5.8.0)
module.js:545
    throw err;
    ^

Error: Cannot find module '/Users/foo/work/grid-styled/npm'

I can get it to run by calling the bin directly: 我可以通过直接调用bin来运行它:

nvm run 9 node_modules/.bin/x0 dev docs/App.js

But it would be better to just call npm. 但是最好只打电话给npm。 Seems possible but the nvm docs don't address this use case. 似乎可能, 但是nvm文档没有解决这个用例。

If you use nvm run you are executing node on a specific version, so: nvm run 9 npm start is equivalent to node npm start (with version 9 of node). 如果使用nvm run您正在特定版本上执行节点,因此: nvm run 9 npm start相当于node npm start (节点版本9)。 That's the reason for the error. 这就是错误的原因。

You should use nvm exec instead, that is for executing a command on specific version, for instance: 您应该使用nvm exec ,即用于在特定版本上执行命令,例如:

$ nvm exec 10 npm -v
Running node v10.0.0 (npm v6.0.0)
6.0.0
$ nvm exec 6 npm -v
Running node v6.10.3 (npm v3.10.10)
3.10.10

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM