node-pi-zero icon indicating copy to clipboard operation
node-pi-zero copied to clipboard

Preserve global `node_modules` during reinstall

Open thisdavej opened this issue 6 years ago • 2 comments

Hi Steven, I experienced an issue with my globally installed npm packages getting wiped. Here are the steps to reproduce on a Pi Zero:

  1. Install Node using an install script such as install-node-v.last.sh
  2. Install npm packages globally such as pm2``: npm install -g pm2`
  3. Install a different version of Node using a script such as install-node-v.lts.sh

After these steps, the pm2 command cannot be invoked and is no longer available as well as any other NPM packages that I installed globally. I see in the install scripts that /opt/nodejs gets wiped every time the install script runs and thus the contents of /opt/nodejs/lib/node_modules containing pm2 gets wiped too.

Can you update the install scripts to preserve the contents of /opt/nodejs/lib/node_modules (with the possible exception of the npm directory which will be regenerated) before doing the installation?

Thanks!

thisdavej avatar Mar 21 '18 00:03 thisdavej

Hi Dave,

Thanks for the feedback but this is not something I'm not looking to implement at the moment.

Aside from the easy workaround (just reinstall them after upgrading/downgrading node), one can't just assume that global modules will work across node versions so its safer/easier to wipe them. The only other way would be to install each node version in its own directory and point the executable there instead, this is the way nvm works but I am not looking to rewrite nvm for the pi at the moment, too much work.

Steven

sdesalas avatar Apr 10 '18 05:04 sdesalas

Hi Steven, my concern is primarily for the many newbies/hobbyists who will be using this. They will have a surprise waiting for them when they implement a small point upgrade from node 9.9.0 to node 9.11.1 and their global modules are wiped. There is no package.json they can npm install to reinstall the global npm packages. They must try to remember the 7 packages they installed globally after first experiencing the consternation of not knowing why http-server, for example, no longer works.

Once again, thanks for maintaining this repository. I use the NodeSource Repositories for my Raspberry Pi systems, but they do not support the Pi Zero (ARMv6 chipsets) so I have been using your solution.

thisdavej avatar Apr 10 '18 14:04 thisdavej