Repository navigation
Can't run npm on node 18.12.1 on Linux #45329
Copy link
Copy link
Closed as not planned
Labels
npmIssues and PRs related to the npm client dependency or the npm registry.Issues and PRs related to the npm client dependency or the npm registry.wrong repoIssues that should be opened in another repository.Issues that should be opened in another repository.
Description
Version
18.12.1 (the archive downloaded directly from site)
Platform
Linux 5.15.0-52-generic #58-Ubuntu SMP Thu Oct 13 08:03:55 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
npm
What steps will reproduce the bug?
Only run npm.
How often does it reproduce? Is there a required condition?
Every time.
What is the expected behavior?
node:internal/modules/cjs/loader:998
throw err;
^
Error: Cannot find module '../lib/cli.js'
Require stack:
- /home/misaka/Libs/node-v18.12.1-linux-x64/bin/npm
at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
at Module._load (node:internal/modules/cjs/loader:841:27)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (/home/misaka/Libs/node-v18.12.1-linux-x64/bin/npm:2:1)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Module._load (node:internal/modules/cjs/loader:878:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/home/misaka/Libs/node-v18.12.1-linux-x64/bin/npm' ]
}
Node.js v18.12.1What do you see instead?
node:internal/modules/cjs/loader:998
throw err;
^
Error: Cannot find module '../lib/cli.js'
Require stack:
- /home/misaka/Libs/node-v18.12.1-linux-x64/bin/npm
at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
at Module._load (node:internal/modules/cjs/loader:841:27)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (/home/misaka/Libs/node-v18.12.1-linux-x64/bin/npm:2:1)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Module._load (node:internal/modules/cjs/loader:878:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/home/misaka/Libs/node-v18.12.1-linux-x64/bin/npm' ]
}
Node.js v18.12.1Additional information
When I edit node-v18.12.1-linux-x64/bin/npm from:
#!/usr/bin/env node
require('../lib/cli.js')(process)To:
#!/usr/bin/env node
require('../lib/node_modules/npm/lib/cli.js')(process)The problem will be solved. But I don't how to make contribution, because I can't understand your source code.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
npmIssues and PRs related to the npm client dependency or the npm registry.Issues and PRs related to the npm client dependency or the npm registry.wrong repoIssues that should be opened in another repository.Issues that should be opened in another repository.
Activity
MrJithil commentedon Nov 6, 2022
Can we try
rm -rf node_modules/ && npm Iand please paste the results for better debugging.Also, is it possible to make a test code snippet?
MegaMraz commentedon Nov 6, 2022
Got this too. Such issues do not occur on nvm or nodesource, only with archive downloaded directly from site.
Devs must be joking. I simply download archive, untar it in /opt/, set PATH to /opt/node/bin.
node --version is working
npm only works with change above
npx also needs a patch:
MegaMraz commentedon Nov 7, 2022
Sorry, I am dumb fox, looks like false alert
When I leave node binary archive in /home and rename it to
node19it works just fine. This is what I have in .bashrc:having it in /opt with root owner and 755 produces issues above. How should I set permissions correctly?
IFirstYou commentedon Nov 8, 2022
I also have this issue
aaw20904 commentedon Nov 14, 2022
Hello! I`m trying to deploy nodejs app on AWS ubuntu EC2 micro instance. I have Node 18.12.1. When I start from my local folder in the remote terminal - it works well. But when I run as a demon - node throws an error where I use an 'import' statament. When I reconfiged a package.json file - the app works well
BlackStar1991 commentedon Nov 14, 2022
I have the same problem on a PC on Windows . After update Node version. Can any fixed this problem?
tuancaraballo commentedon Nov 15, 2022
I had the same issue running
rm -rf node_modules && npm ifixed it for me.aaw20904 commentedon Nov 15, 2022
Yesterday I started to fix the problem.I found out - when Nodejs runs as a service (I used systemctl for running the one) then It doesn
t work correct: [case A]: ES6 import/export isnt working - the interpreter throws an error.But require() works well))[case B]: When you use a private members in classes (for example - '#myPropery, #myMethod() ') - the nodejs throws an error << Error: Cannot find module 'testlib.js' >>.
! BUT ! When I run a script in a terminal (not as a service) - it works well with import/export and private members of a class.
My target system - AWS EC2 micro Ubntu 20 LTS.
I have NO idea how to fix it. Can we avoid using private members and import/export in the Nodejs when a target system is Linux?
[-]Can't run npm on node 18.12.1 on Linux[/-][+]Can't run `npm` on node 18.12.1 on Linux[/+]antoniomormile commentedon Nov 30, 2022
I got a similar error when I imported bcrypt package.
Error: Cannot find module 'bcrypt' nestjs-be-nest-1 | Require stack: nestjs-be-nest-1 | - /usr/src/app/dist/src/auth/controllers/register.controller.js nestjs-be-nest-1 | - /usr/src/app/dist/src/auth/auth.module.js nestjs-be-nest-1 | - /usr/src/app/dist/src/app.module.js nestjs-be-nest-1 | - /usr/src/app/dist/src/main.js nestjs-be-nest-1 | at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1039:15) nestjs-be-nest-1 | at Function.Module._load (node:internal/modules/cjs/loader:885:27) nestjs-be-nest-1 | at Module.require (node:internal/modules/cjs/loader:1105:19) nestjs-be-nest-1 | at require (node:internal/modules/cjs/helpers:103:18) nestjs-be-nest-1 | at Object.<anonymous> (/usr/src/app/src/auth/controllers/register.controller.ts:12:1) nestjs-be-nest-1 | at Module._compile (node:internal/modules/cjs/loader:1218:14) nestjs-be-nest-1 | at Object.Module._extensions..js (node:internal/modules/cjs/loader:1272:10) nestjs-be-nest-1 | at Module.load (node:internal/modules/cjs/loader:1081:32) nestjs-be-nest-1 | at Function.Module._load (node:internal/modules/cjs/loader:922:12) nestjs-be-nest-1 | at Module.require (node:internal/modules/cjs/loader:1105:19)drexler commentedon Dec 2, 2022
I have the same problem attempting to build on Mac OS 13.01
dj0024javia commentedon Dec 9, 2022
Yup, This is happening with es build as well.

Nodejs 18.12.0
This was not happening in older node version as i tried to rebuild the same repo that i built 6 months back and it was working fine then.
devk232 commentedon Dec 18, 2022
I got the same error on the windows:
dj0024javia commentedon Dec 22, 2022
If anyone is trying to build using esbuild, i got error using that. Switched to aws-cdk Lambda stack which has esbuild in built, solved my issue. I guess it has something to do with the configration in the esbuild.config.js file
bnoordhuis commentedon Dec 23, 2022
I'll close this because this ultimately looks like an npm issue and those should be reported to npm, not here. Node bundles npm but doesn't maintain it.
N00bSkywalker commentedon Apr 19, 2023
For anyone getting here and seeing the same error, I was also able to reproduce this, albeit accidentally. I'm using a Python script to download & extract node-v18.16.0-linux-x64.tar.xz to a temp directory ... and the contents of that temp directory are then copied to a final location via shutil.copytree(). Problem ended up being that the default for shutil.copytree() is to not preserve symbolic links ... which is why npm & npx failed to run (they're supposed to be links!).
When downloading via wget & extracting via tar, with no interim directory or copying involved, symlinks were preserved, and npm & npx ran as expected.