Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't run npm on node 18.12.1 on Linux #45329

Closed
vvvbbbcz opened this issue Nov 5, 2022 · 15 comments
Closed

Can't run npm on node 18.12.1 on Linux #45329

vvvbbbcz opened this issue Nov 5, 2022 · 15 comments
Labels
npm Issues and PRs related to the npm client dependency or the npm registry. wrong repo Issues that should be opened in another repository.

Comments

@vvvbbbcz
Copy link

vvvbbbcz commented Nov 5, 2022

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.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/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.

@MrJithil
Copy link
Member

MrJithil commented Nov 6, 2022

Can we try rm -rf node_modules/ && npm I and please paste the results for better debugging.

Also, is it possible to make a test code snippet?

@MegaMraz
Copy link

MegaMraz commented 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:

- 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')

@MegaMraz
Copy link

MegaMraz commented Nov 7, 2022

Sorry, I am dumb fox, looks like false alert

When I leave node binary archive in /home and rename it to node19 it works just fine. This is what I have in .bashrc:

export NODEJS_HOME=/home/megamraz/Apps/node19/bin
export PATH=$NODEJS_HOME:$PATH

having it in /opt with root owner and 755 produces issues above. How should I set permissions correctly?

@mhcrocky
Copy link

mhcrocky commented Nov 8, 2022

Version

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/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.

I also have this issue

@aaw20904
Copy link

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
Copy link

I have the same problem on a PC on Windows . After update Node version. Can any fixed this problem?

@tuancaraballo
Copy link

I had the same issue running rm -rf node_modules && npm i fixed it for me.

@aaw20904
Copy link

aaw20904 commented 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 doesnt 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?

@vvvbbbcz vvvbbbcz 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 Nov 19, 2022
@antoniomormile
Copy link

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
Copy link

drexler commented Dec 2, 2022

I have the same problem attempting to build on Mac OS 13.01

@dj0024javia
Copy link

Yup, This is happening with es build as well.
image

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
Copy link

devk232 commented Dec 18, 2022

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.1

@dj0024javia
Copy link

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
Copy link
Member

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.

@bnoordhuis bnoordhuis closed this as not planned Won't fix, can't repro, duplicate, stale Dec 23, 2022
@bnoordhuis bnoordhuis added npm Issues and PRs related to the npm client dependency or the npm registry. wrong repo Issues that should be opened in another repository. labels Dec 23, 2022
@N00bSkywalker
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
npm Issues and PRs related to the npm client dependency or the npm registry. wrong repo Issues that should be opened in another repository.
Projects
None yet
Development

No branches or pull requests