Bundle `nodejs-basic` should not manage anything in `/usr/lib/node_modules`

Currently npm and yarn is included in bundle nodejs-basic. This is good, but this may also bring some problems.

Some files included in nodejs-basic might be modified when updating npm or yarn by executing sth. like npm i -g npm. This can be confirmed by

  • install nodejs-basic
  • then run npm i -g npm
  • then swupd diagnose.

Here is a part of the output:

Checking for missing files
 -> Missing file: /usr/lib/node_modules/npm/node_modules/block-stream
 -> Missing file: /usr/lib/node_modules/npm/node_modules/block-stream/LICENCE
 -> Missing file: /usr/lib/node_modules/npm/node_modules/block-stream/LICENSE
 -> Missing file: /usr/lib/node_modules/npm/node_modules/block-stream/README.md
...

This can be a trouble esp when nodejs-basic needs to upgrade. Doing so may break npm’s versioning system, esp when nodejs-basic is not shipping newest version of npm.

Anyway, /usr/lib/node_modules should always be managed by npm solely. swupd or nodejs-basic should never touch it.

I think we need npm to use e.g. /usr/local/lib/node_modules by default - would that solve the problem?

1 Like

That seems work. So maybe just setting env var or global npmrc to point npm prefix to /usr/local should just work, right.

Another problem, what if both /usr/local/bin/npm and /usr/bin/npm exists ?

The /usr/local/bin/npm version should be used in that case because /usr/local/bin/is before /usr/bin in $PATH

1 Like