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

[BUG] all commands fail: TypeError: LRU is not a constructor #6785

Closed
2 tasks done
iambumblehead opened this issue Sep 10, 2023 · 19 comments
Closed
2 tasks done

[BUG] all commands fail: TypeError: LRU is not a constructor #6785

iambumblehead opened this issue Sep 10, 2023 · 19 comments
Labels
Awaiting Information further information is requested Bug thing that needs fixing Release 10.x

Comments

@iambumblehead
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

npm --version and other commands print a runtime error

$ npm --version
/usr/lib/node_modules/npm/lib/es6/validate-engines.js:31
    throw err
    ^

TypeError: LRU is not a constructor
    at Object.<anonymous> (/usr/lib/node_modules/npm/node_modules/semver/classes/range.js:188:15)
    at Module._compile (node:internal/modules/cjs/loader:1241:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
    at Module.load (node:internal/modules/cjs/loader:1091:32)
    at Module._load (node:internal/modules/cjs/loader:938:12)
    at Module.require (node:internal/modules/cjs/loader:1115:19)
    at require (node:internal/modules/helpers:130:18)
    at Object.<anonymous> (/usr/lib/node_modules/npm/node_modules/semver/functions/satisfies.js:1:15)
    at Module._compile (node:internal/modules/cjs/loader:1241:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)

Expected Behavior

npm commands should not fail with a runtime error

$ npm --version
10.0.0-1

Steps To Reproduce

  1. install npm
  2. use any npm command, such as "npm --version", "npm install" or "npm test".
  3. see runtime error

Environment

  • npm: 10.0.0-1
  • Node.js: v20.6.0
  • OS Name: Arch Linux
  • System Model Name: xps13
  • npm config: (generated from the previous, working version of npm, version 9.8.1)
; "user" config from /home/bumble/.npmrc

//registry.npmjs.org/:_authToken = (protected) 

; node bin location = /usr/bin/node
; node version = v20.6.0
; npm local prefix = /home/bumble/software/esmock
; npm version = 9.8.1
; cwd = /home/bumble/software/esmock
; HOME = /home/bumble
; Run `npm config ls -l` to show all defaults.
@iambumblehead iambumblehead added Bug thing that needs fixing Needs Triage needs review for next steps Release 10.x labels Sep 10, 2023
@lukekarrys
Copy link
Contributor

lukekarrys commented Sep 11, 2023

Can you try [email protected] which is the latest versions? Also how did you download this version of npm? 10.0.0-1 isn't a valid version of npm in the registry:

npm view npm --json versions
[
  ...
  "10.0.0-pre.0",
  "10.0.0-pre.1",
  "10.0.0",
  "10.1.0"
]

@lukekarrys lukekarrys added Awaiting Information further information is requested and removed Needs Triage needs review for next steps labels Sep 11, 2023
@iambumblehead
Copy link
Author

@lukekarrys thank you and my apology for opening this issue here. This should have been opened at the arch package location instead https://gitlab.archlinux.org/archlinux/packaging/packages/npm/-/blob/main/PKGBUILD?ref_type=heads

respectfully, I will close this issue

@blacklight
Copy link

@iambumblehead I've been experiencing the same issue on all of my Arch installations as well after upgrading to npm 10.

Downgrading to 9.8.1 is a temporary workaround.

Have you already reported the issue to the Arch maintainer? I couldn't find anything here https://bugs.archlinux.org/?project=1&string=npm.

I can open a ticket on the Arch side as well if you prefer.

@iambumblehead
Copy link
Author

@blacklight please open a ticket :) I do not have an account there and did not open a ticket

@blacklight
Copy link

@iambumblehead ok FYI I've filed a bug report on Arch here https://bugs.archlinux.org/task/79693

@iambumblehead
Copy link
Author

thanks. toolybird's comment un-necessarily rude

@blacklight
Copy link

@iambumblehead I've found the culprit and a solution - see comment on the Arch Linux thread.

Long story short, the error most likely happens when you have (or had at some point) an old version of semver installed - either an old semver package or something installed via npm install -g.

Uninstalling npm+semver, removing /usr/lib/node_modules/npm/node_modules/semver and reinstalling it should fix it.

@iambumblehead
Copy link
Author

@blacklight yes that works thank you!

$ sudo pacman -R npm semver node-gyp
$ sudo rm -rf /usr/lib/node_modules/npm/node_modules/semver
$ sudo pacman -S npm semver
$ npm --version
10.1.0

@br4nnigan
Copy link

@iambumblehead I've found the culprit and a solution - see comment on the Arch Linux thread.

Long story short, the error most likely happens when you have (or had at some point) an old version of semver installed - either an old semver package or something installed via npm install -g.

Uninstalling npm+semver, removing /usr/lib/node_modules/npm/node_modules/semver and reinstalling it should fix it.

I'm curious, how tf did you find that out?

@antonis-tsolomitis
Copy link

The above fix does not work now. After
sudo pacman -Syu
sudo pacman -R npm semver node-gyp
rm -rf /usr/lib/node_modules/npm/node_modules/semver
sudo pacman -S npm semver

The command

npm --version

gives
/usr/lib/node_modules/npm/lib/es6/validate-engines.js:31
throw err
^

TypeError: LRU is not a constructor
at Object. (/usr/lib/node_modules/npm/node_modules/npm-package-arg/node_modules/hosted-git-info/index.js:6:15)
at Module._compile (node:internal/modules/cjs/loader:1375:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1434:10)
at Module.load (node:internal/modules/cjs/loader:1206:32)
at Module._load (node:internal/modules/cjs/loader:1022:12)
at Module.require (node:internal/modules/cjs/loader:1234:19)
at require (node:internal/modules/helpers:176:18)
at Object. (/usr/lib/node_modules/npm/node_modules/npm-package-arg/lib/npa.js:8:19)
at Module._compile (node:internal/modules/cjs/loader:1375:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1434:10)

Node.js v21.5.0

@ljharb
Copy link
Collaborator

ljharb commented Feb 11, 2024

Why would you install an npm package via pacman? use npm.

@blacklight
Copy link

blacklight commented Feb 11, 2024

Why would you install an npm package via pacman? use npm.

Installing packages via npm install -g is exactly what seems to cause the issue in these cases.

When npm is upgraded via pacman it also upgrades anything under /usr/lib/node_modules, if those packages were installed via pacman too.

If they were installed via npm instead, then those old dependencies are likely to stay there. If they are incompatible with the new version of npm, then you'll have this kind of errors.

As a general advice, global packages should always be installed through the system package manager, if they are available. npm install -g is likely to break system dependencies just like sudo pip install.

The above fix does not work now

If the error doesn't come from gyp/semver now then it may come from another dependency installed via npm install -g.

My way of pinpointing the culprit usually works, but it's a bit cumbersome - not sure if there's a smarter way of telling which dependencies weren't installed via pacman.

  1. Backup your /usr/lib/node_modules and /usr/local/lib/node_modules folders and remove them
  2. Reinstall node+npm
  3. Verify that the error no longer occurs
  4. Reinstall all the dependencies in your previous node_modules via pacman. Or try and move the modules folders back one by one to test which one causes the error

@antonis-tsolomitis
Copy link

I backed up each of the above folder and removed it.
pacman -R npm semver node-gyp

then

pacman -S npm

accepted the semver and node-gyp dependencies and all installed.

Now npm --version fails again, now with:

/usr/lib/node_modules/npm/lib/es6/validate-engines.js:31
throw err
^

Error: Cannot find module 'nopt'
Require stack:

  • /usr/lib/node_modules/npm/node_modules/@npmcli/config/lib/index.js
  • /usr/lib/node_modules/npm/lib/npm.js
  • /usr/lib/node_modules/npm/lib/cli-entry.js
  • /usr/lib/node_modules/npm/lib/cli.js
  • /usr/lib/node_modules/npm/bin/npm-cli.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1143:15)
    at Module._load (node:internal/modules/cjs/loader:984:27)
    at Module.require (node:internal/modules/cjs/loader:1234:19)
    at require (node:internal/modules/helpers:176:18)
    at Object. (/usr/lib/node_modules/npm/node_modules/@npmcli/config/lib/index.js:4:14)
    at Module._compile (node:internal/modules/cjs/loader:1375:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1434:10)
    at Module.load (node:internal/modules/cjs/loader:1206:32)
    at Module._load (node:internal/modules/cjs/loader:1022:12)
    at Module.require (node:internal/modules/cjs/loader:1234:19) {
    code: 'MODULE_NOT_FOUND',
    requireStack: [
    '/usr/lib/node_modules/npm/node_modules/@npmcli/config/lib/index.js',
    '/usr/lib/node_modules/npm/lib/npm.js',
    '/usr/lib/node_modules/npm/lib/cli-entry.js',
    '/usr/lib/node_modules/npm/lib/cli.js',
    '/usr/lib/node_modules/npm/bin/npm-cli.js'
    ]
    }

Node.js v21.5.0

@antonis-tsolomitis
Copy link

antonis-tsolomitis commented Feb 11, 2024

Ah, I installed nodejs-nopt and now it works! Thank you.

The folders I had backed up are: corepack, root, vdx and node-gyp, nopt, npm, semver which where installed again by pacman. I guess these are needed... how do I install them with pacman (I mean corepack, root, vdx)?

@blacklight
Copy link

how do I install them with pacman (I mean corepack, root, vdx)?

It may be that they are no longer required by recent versions of node - I'm on the latest version and my node_modules doesn't seem to contain those folders any longer.

@antonis-tsolomitis
Copy link

OK. Great!

@devsnd
Copy link

devsnd commented Apr 7, 2024

I had a few other modules that did not work after having reinstalled npm and semver as recommended by @blacklight .

I also needed to manually delete the node_modules that were part of the npm install, so to fix it on arch I did:

$ sudo pacman -R npm semver node-gyp
$ sudo rm -rf /usr/lib/node_modules/npm  # note that I removed the whole npm directory this time
$ sudo pacman -S npm semver
$ npm --version
v21.7.2

Note: This obviously nukes your globally installed node_modules, but I wanted a clean state to work off of

@sarthakgupta898
Copy link

What is the workaround for windows?

@AlonaAkimova
Copy link

AlonaAkimova commented Apr 24, 2024

Hello,

Error is in this line: https://github.com/npm/node-semver/blob/ec49cdcece9db0020d6829b246681ff65a393644/classes/range.js#L201

It has been introduced in semver 7.3.3.

The new version 7.6.1 is released and will solve the problem. Related MR here:
npm/node-semver#706.

Solution is to upgrade to 7.6.1 or downgrade to 7.3.2

If you want to downgrade add below to your package.json:

NPM:

{
   "overrides": {
     "semver": "7.3.2"
   }
 }

Yarn:

"resolutions": {
    "semver": "7.3.2"
}

Hope it helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Information further information is requested Bug thing that needs fixing Release 10.x
Projects
None yet
Development

No branches or pull requests

9 participants