Problem - npm: not found

Good afternoon, everyone.
Please help.

root@GigaIII-YN:/opt/bin$ node -v
v16.16.0

Decided to update NPM:
npm install -g npm@9.2.0

As a result:

root@GigaIII-YN:/opt/bin$ npm -v
/opt/bin/sh: npm: not found
root@GigaIII-YN:/opt/bin$ which npm
/opt/bin/npm

What to do?

How did you install node ?

knolleary
Thank you very much for responding.
Your simple question took me a lot of time to bring up all the records from 2 years ago.

I Install it like this more than 2 years ago.

  1. Downloaded the file:
    http://bin.entware.net/mipselsf-k3.4/installer/mipsel-installer.tar.gz
  2. Created the Install folder on the flash drive
  3. Copied the downloaded file into it
  4. Inserted the USB flash drive into the router and waited for the installation to finish
  5. Completed:
    opkg install http://bin.entware.net/mipselsf-k3.4/test/node-red_1.1.3-1_mipsel-3.4.ipk
  6. The packages of Node RED itself were installed through its Web GUI.

@Yury I am asking about node.js, rather than Node-RED.

Your original post says you have Node v16.16.0 - which is quite recent. So you must have installed/updated it more recently than two years ago.

A normal node.js install will include npm. For some reason it is not included for you.

What platform/os is this on? The instructions you've shared for installing Node-RED are not ones I recognise - they certainly haven't come from us. So is this a custom piece of hardware you are using? Or a particular OS that provides its own packages for node.js and node-red?

знаток
You are absolutely right, I updated to this version a month ago. Originally there was, of course, a younger version.
And until today, there was also npm. But after it was removed by the
npm install -g npm@9.2.0
and the system stopped seeing him.

In my case, today NodeRed is a NodeJS package, which itself is a package of system Entware. And this system is deployed on the Linux operating system, which runs on a home router.
Which, of course, is very convenient and, most importantly, reliable. For 4 years, I have never had any NodeRed failures, not counting those caused by my inexperience. I was among the first in the country who started working on such hardware.

Taking this opportunity, I would like to thank you from the bottom of my heart for your work in creating and developing such a wonderful programming environment.

What does this show
ls -l /opt/bin/npm
if it says it is a link to somewhere else, does that file exist? If not then I suspect that npm has been installed somewhere else.

Thank you for advice:

root@GigaIII-YN:/opt/bin$ ls -l /opt/bin/npm
lrwxrwxrwx    1 root     1000            38 Dec  8 12:01 /opt/bin/npm -> ../lib/node_modules/npm/bin/npm-cli.js

This file /opt/bin/npm:

#!/usr/bin/env node
require('../lib/cli.js')(process)

This file /opt/lib/node_modules/npm/bin/npm-cli.js:

#!/usr/bin/env node
require('../lib/cli.js')(process)

/opt/bin/npm and /opt/lib/node_modules/npm/bin/npm-cli.js are the same file (as the first is just a link to the second.

Does the required file exist? /opt/lib/node_modules/npm/lib/cli.js

Yes, it exists. And as far as I understand, it is executable (there is an asterisk in the MC).

But

root@GigaIII-YN:/opt/lib/node_modules/npm/bin$  npm -v
/opt/bin/sh: npm: not found
root@GigaIII-YN:/opt/lib/node_modules/npm/lib$  npm.js -v
/opt/bin/sh: npm.js: not found

lib
bin

It is cli.js not npm.js
To execute a file that is not in the path you have to address it directly, so from that folder it would be
./cli.js
But I don't think that file is supposed to be executed directly.

Sorry, I have no idea what is going on, possibly the npm you have installed is not compatible with the node.js that you have. The only suggestion that I have is to uninstall node.js and npm and then reinstall node.js, which should give you a working version of npm that is compatible with nodejs 16. Then don't try to upgrade npm to a later version.

Colin
Even if it is not clear to you - an experienced one - then, of course, I will follow your advice and I will do it right now.
I will put everything from the very beginning

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.