Gutenberg: To what extent is NVM needed for the local environment?

Created on 18 Aug 2018  Â·  6Comments  Â·  Source: WordPress/gutenberg

I cloned the repo and ran ./bin/setup-local-env.sh, it wants me to install nvm. I use n so installing nvm as well could cause conflicts.

Couldn't the bin/install-node-nvm.sh script just check if I have an up to date node version and just skip all that?

To what extent is the nvm needed? If I comment out the nvm part is that going to cause problems?

[Type] Build Tooling [Type] Question

All 6 comments

I hit this too (having been happily using n for quite a while).

To get you up and running:

  • n lts will get you the Node version the script is looking for.
  • Open bin/setup-local-env.sh, and replace the . "$(dirname "$0")/install-node-nvm.sh" line with npm install (that's the one piece from that script you really need).
  • Run ./bin/setup-local-env.sh, and you will get the expected startup process.

I tend to agree, having nvm so deeply engrained isn't the best experience – the script may require adding a new dotfile, and will quietly upgrade npm, two side effects which may not be appreciated by everyone. Granted, if a developer _is_ starting from scratch, it's pretty darn convenient.

Two options forward would be:

  • Work checks using the n binary into the existing script. It'll get kinda messy quickly though :/
  • Simplify the script to just do the checks, and leave nvm (or n!) installation up to the user.

I'd probably lean to the latter.

I've had similar issues, though in my case I use the Fish Shell and nvm is tricky with fish, so much so that I actually use a custom function named nvm to have _nvm_ functionality, though its not 100% compatible and one of the conflicts I have is basically the same as above, nvm is not detected by the ./bin/setup-local-env.sh script and therefore fails.

I'm not sure on the ideal solution either, to be honest, it would be great to explore some of the options already listed above though

Noting that as of now, the above hack no longer works, and everything hangs in package installation. I eventually gave up, removed n, and went with nvm 😞 .

I don't think that nvm is necessary at all. It's mostly there to ensure that Travis runs with the latest version of node and npm. It should be perfectly fine to add logic to the ./bin/setup-local-env.sh which detects n and uses it instead as well. I'm closing this issue. If you think that we should add detection of n, feel free to open another issue.

Related code:
https://github.com/WordPress/gutenberg/blob/e21255689c5299bb865efdea5ca1d0543a379d60/bin/setup-local-env.sh#L15-L16
https://github.com/WordPress/gutenberg/blob/e21255689c5299bb865efdea5ca1d0543a379d60/bin/install-node-nvm.sh

None of this should be an issue anymore with the merge of #17004 :

Much like the WordPress environment, however, I've aimed to not automate everything. As we found with the Gutenberg environment, too much automation tended to make it difficult (particularly for more advanced contributors) to customise or debug their environment. For example, the scripts no longer install NVM, switch your Node version, or run npm install.

🎉

The .nvmrc file is still there, so you can use NVM if you prefer it. It's no longer a requirement for the automated environment scripts, though.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

melchoyce picture melchoyce  Â·  95Comments

tofumatt picture tofumatt  Â·  86Comments

DeveloperWil picture DeveloperWil  Â·  102Comments

maddisondesigns picture maddisondesigns  Â·  79Comments

smp303 picture smp303  Â·  98Comments