Repository navigation
Can't run npm on node 18.12.1 on Linux #45329
Description
Activity
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?
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:
- const cli = require('../lib/cli.js') + const cli = require('../lib/node_modules/npm/lib/cli.js') ... - process.argv[1] = require.resolve('./npm-cli.js') + process.argv[1] = require.resolve('../lib/node_modules/npm/bin/npm-cli.js') ... - const { definitions, shorthands } = require('../lib/utils/config/index.js') + const { definitions, shorthands } = require('../lib/node_modules/npm/lib/utils/config/index.js')
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:export NODEJS_HOME=/home/megamraz/Apps/node19/bin export PATH=$NODEJS_HOME:$PATHhaving it in /opt with root owner and 755 produces issues above. How should I set permissions correctly?
Reacted by Jithil P Ponnan and LoganVersion
18.12.1
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.1
What 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.1
Additional information
When I edit
node-v18.12.1-linux-x64/bin/npmfrom:#!/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.
I also have this issue
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
I have the same problem on a PC on Windows . After update Node version. Can any fixed this problem?
I had the same issue running
rm -rf node_modules && npm ifixed it for me.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?- changed the title
[-]Can't run npm on node 18.12.1 on Linux[/-][+]Can't run `npm` on node 18.12.1 on Linux[/+]on Nov 19, 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)I have the same problem attempting to build on Mac OS 13.01
I got the same error on the windows:
node:internal/modules/cjs/loader:998 throw err; ^ Error: Cannot find module '../lib/cli.js' Require stack: - C:\Users\devsa\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js 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> (C:\Users\devsa\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js: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: [ 'C:\\Users\\devsa\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js' ] } Node.js v18.12.1If 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
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.
- addednpmIssues 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.
on Dec 23, 2022 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.

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?
What do you see instead?
Additional information
When I edit
node-v18.12.1-linux-x64/bin/npmfrom:To:
The problem will be solved. But I don't how to make contribution, because I can't understand your source code.