Score:1

node/nvm/npm installations : sudo vs. user install leads to trouble?

ly flag

The problem appears to be inconsistency with root and user installed node (v.19.7.0), nvm (0.39.3), and npm (v. 9.5.0) and a specific npm-installed package called svg-path-interpolator on an Ubuntu 22.0.4 system. Should node, nvm and npm all be uninstalled and reinstalled as user, or go through each piecemeal - or is it going to work if everything is left as-is? Perhaps I should note that this is just to get one script to run calculations at the user level, i.e. not for a website to handle lots of web traffic etc.

Background: I have naively tried getting javascript code to run described here. The specific package is called svg-path-interpolator. There are a number of problems with that project, which led me to scrutinize the installation of node, nvm, and npm - even though simple checks with some simple java scripts e.g. from tutorials or the node website work ok. I think it is good that the version of node is turning out to be the "right" one, e.g. 19.7.0.

It appears my approach to install npm, nvm, and node (at least) was also naive. The commands I used, in order (I think), were:

sudo apt install npm

sudo npm install -g svg-path-interpolator

sudo npm install svg-path-interpolator --save

npm install svg-path-interpolator(AT SOME POINT)

sudo apt install node (PROBABLY)

Note that npm was ran first locally, no special permissions. The script I want to run didn't work, so naturally I ran npm "globally", and naturally, the script didn't work. The help page says In global mode (ie, with -g or --global appended to the command), it installs the current package context (ie, the current working directory) as a global package. - and I have read this idea elsewhere - what does that mean, that the CWD is being used somehow?

I also tried the --save option. From reading further - especially regarding permissions and working directory - it appears this willy-nilly user vs. admin installation is bad. Some evidence on my system is (excerpts) :

ls -ltraF /home/user/package-lock.json
-rw-r--r-- 1 root root 2091 Mar  5 11:46 /home/user/package-lock.json
ls -ltraF ~/node_modules/.package-lock.json 
-rw-r--r-- 1 root root 1117 Mar  5 11:46 /home/user/node_modules/.package-lock.json

I also see that svg-path-interpolator is missing from:

/home/user/.nvm/versions/node/v19.7.0/lib/node_modules/npm/node_modules/

there's also node_modules in /usr/local/lib, so it is confusing.

One last clue : in trying to get the original task to work, another error is worrisome (but this might be irrelevant) :

./svgpi.mjs config.json  balloons.svg  output.json
[Error: ENOENT: no such file or directory, mkdir ''] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'mkdir',
  path: ''
}

To solve that, I might have run the script with sudo once to see what would happen, but it seemed not to do anything (I hope).

So perhaps instead of the dreaded complete uninstall and reinstall but-only-as-user, I could leave things be and simply get rid of package-lock.json and write it out as user somehow by following the guidance in the npm or nvm man pages/web pages or Stack Exchange posts - which I have been following carefully. I tried to cover the bases but again I have a long post because the specific thing to ask about or do is unclear - apologies.

Levente avatar
cn flag
`sudo npm install -g svg-path-interpolator` I would never do this specifically, in other words never execute npm with sudo rights for installing an additional user-space script. Additionally, since at this point some files were overwritten with an ownership to root, every other subsequent command can be suspect of running improperly when attempted to run at the normal user level.
Bryan-StackExchange avatar
ly flag
I'm not sure how else it would be installed "globally", which I thought ```-g``` means - in the README here : https://github.com/justinwilaby/svg-path-interpolator#readme ...
pl flag
Depends who you ask. Some people don't like 3rd party package managers (like npm and pip) installing files all over the filesystem, outside the users home. Others care less, and if anything goes wrong, blame Ubuntu :D
Score:0
ly flag

This seemed to get things moving along:

The whole point is to run a little script installed by npm (described in links above). BTW had to run dos2unix on that script. Manually did export PATH=$PATH:/home/user/node_modules/my-favorite-module-package/bin/. Relevant tech detail : the .mjs file had await fs.mkdir(dir, {recursive: true});. This produced an ENOENT error -2 when script is run as instructed - with an output file. Because there was a mkdir in that construct in the .mjs. I omitted the output file, and the process completes (apparently, properly). Omitting the output file was not obvious. All (... most of) the things I wrote in this answer were found by using a search engine and picking usually the top hits which usually / preferentially were on Stack Overflow or Stack Exchange - i.e. it's all in here.

I'm leaving the nvm,node, npm, and whatever else (like java or curl-installed stuff from even long ago) alone - over time, maybe do something with the root-owned package things. Not sure why the PATH isn't automagically set after all that, but oh well.

Not strictly an answer but a workaround - one might read the Meta S.E. for an idea of how workaround v. answer is treated on Stack Exchange. Spoiler : workarounds can be answers.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.