There is one app in which has dependencies that only work with latest node v13. We want to use node v13 for that app.
I have a script in package.json called "test": "ava".
But I can't seem to run my tests with n.
My steps:
npm i -g nsudo n latestsudo n then select the latest versionThis is logged:
installed : v13.7.0 to /usr/local/bin/node
active : v12.13.1 at /usr/local/opt/node@12/bin/node
then I go to my project dir and try this:
n run 13.7.0 npm run test
Error: Cannot find module '/my-project-dir/npm'
If I try to run ava directly, I get the same error that it can't find ava.
$ n --version
? 6.1.3
$ command -v node
? /usr/local/opt/node@12/bin/node
$ node -p process.platform
? darwin
Two tips:
1) You have a version of node installed earlier in your PATH than the location n is using, so changing the version using n won't be changing what gets run when you type node. This message is warning you that although n did install a node version, the active version is different.
installed : v13.7.0 to /usr/local/bin/node
active : v12.13.1 at /usr/local/opt/node@12/bin/node
(I don't recognise the path style and not sure what installed: /usr/local/opt/node@12/bin/node.)
2) n run is actually running a particular version of node. To run other things that use node (like npm or ava) try n exec instead. exec was added specifically for this sort of situation.
Hi @shadowspawn Thanks for the detailed information!
Two small follow-up questions.
I originally installed node via homebrew like so:
brew install node@12
in this case, what is the recommended way to install and use n ?
is n supposed to be used on a execute basis ? or are we supposed to switch node version repeatedly any time we want to set the global node version to something else?
Eg. if I want to keep using node version 12 by default, but only use n to use node v13 for that one project
I originally installed node via homebrew ...
in this case, what is the recommended way to install and usen
I think it is personal preference whether you use npm or brew to install and update n. I personally use npm. (An initial advantage in using brew is bypassing the bootstrapping problem of npm being a convenient way to install n!)
I recommend only having one node on your PATH, so I suggest you try uninstalling the homebrew copy of node. (Make a list of your global npm modules first as you will probably want to reinstall them in the new location, npm list -g --depth=0.)
is n supposed to be used on a execute basis ? or are we supposed to switch node version repeatedly any time we want to set the global node version to something else?
The normal use case for n is changing the globally installed node version.
The execute basis is intended for more limited use to test a specific version without changing the globally installed version, like in scripts in your one special project.
thank you very much
Most helpful comment
Two tips:
1) You have a version of node installed earlier in your PATH than the location
nis using, so changing the version usingnwon't be changing what gets run when you typenode. This message is warning you that althoughndid install a node version, the active version is different.(I don't recognise the path style and not sure what installed:
/usr/local/opt/node@12/bin/node.)2)
n runis actually running a particular version of node. To run other things that use node (like npm or ava) tryn execinstead.execwas added specifically for this sort of situation.