RHEL 9 npm command not recognized

354 views Asked by At

I am trying to install nodejs,npm, and npx on my Red Hat Enterprise 9 server, but I am running into a snag. I have tried installing nodejs through the binary, npm, yum, and dnf (apt-get doesn't exist on RHEL). I am trying to install nodejs 19.x.

I have gotten to the point where node commands work, however all npm and npx commands return this weird error.

  throw err;
  ^

Error: Cannot find module '/home/kanm/Downloads/sam/node'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1090:15)
    at Module._load (node:internal/modules/cjs/loader:934:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
    at node:internal/main/run_main_module:23:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v19.9.0

To try and resolve this, I have removed all node files using these commands: sudo find / -name node and sudo find / -name npm and removing them. Then, I also ran, sudo yum remove nodejs and sudo dnf remove nodejs and commands from this post.

My current guess as to what is wrong is this is a problem with a hidden source command from a previous nvm or broken installation. Another weird thing is, yarn commands work perfectly until an npm or npx command is ran in a dependency.

I currently have node installed using yum. I used this tutorial to install from the NodeSource repository. The which commands return the following directories:


[kanm@kanm-server sam]$ which node
/usr/bin/node
[kanm@kanm-server sam]$ which npm
/usr/bin/npm

The directory looks like this:


[kanm@kanm-server sam]$ ls -l /usr/bin | grep node
lrwxrwxrwx  1 root root          45 Apr 10 14:36 corepack -> ../lib/node_modules/corepack/dist/corepack.js
-rwxr-xr-x  1 root root    93298360 Apr 10 14:36 node
lrwxrwxrwx  1 root root          38 Apr 10 14:36 npm -> ../lib/node_modules/npm/bin/npm-cli.js
lrwxrwxrwx  1 root root          38 Apr 10 14:36 npx -> ../lib/node_modules/npm/bin/npx-cli.js

Any expertise or opinions on what may be wrong are welcome. I am very lost lol.

0

There are 0 answers