You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] all commands fail: TypeError: LRU is not a constructor #6785
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
install npm
use any npm command, such as "npm --version", "npm install" or "npm test".
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.
Can you try npm@10.1.0 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:
@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.
Reacted by Nihan Mubashshir, Nathan Chere, Enigmind, Morgan Askins, br4nnigan, Andrey Zhabsky, Sven Eberth, Simon Pera, juanmah, Davide Gessa and 13 more
@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?
Reacted by Davide Gessa, Thornhill, Ankit Jain and Erik Slovák
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
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)
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.
Backup your /usr/lib/node_modules and /usr/local/lib/node_modules folders and remove them
Reinstall node+npm
Verify that the error no longer occurs
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
/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'
]
}
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)?
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.
Activity
lukekarrys commentedon Sep 11, 2023
Can you try npm@10.1.0 which is the latest versions? Also how did you download this version of npm?
10.0.0-1isn't a valid version of npm in the registry:iambumblehead commentedon Sep 11, 2023
@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 commentedon Sep 14, 2023
@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 commentedon Sep 14, 2023
@blacklight please open a ticket :) I do not have an account there and did not open a ticket
blacklight commentedon Sep 14, 2023
@iambumblehead ok FYI I've filed a bug report on Arch here https://bugs.archlinux.org/task/79693
iambumblehead commentedon Sep 14, 2023
thanks. toolybird's comment un-necessarily rude
blacklight commentedon Sep 14, 2023
@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/semverand reinstalling it should fix it.iambumblehead commentedon Sep 15, 2023
@blacklight yes that works thank you!
br4nnigan commentedon Oct 8, 2023
I'm curious, how tf did you find that out?
antonis-tsolomitis commentedon Feb 11, 2024
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 commentedon Feb 11, 2024
Why would you install an npm package via pacman? use npm.
blacklight commentedon Feb 11, 2024
Installing packages via
npm install -gis exactly what seems to cause the issue in these cases.When
npmis upgraded viapacmanit also upgrades anything under/usr/lib/node_modules, if those packages were installed viapacmantoo.If they were installed via
npminstead, then those old dependencies are likely to stay there. If they are incompatible with the new version ofnpm, 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 -gis likely to break system dependencies just likesudo pip install.If the error doesn't come from
gyp/semvernow then it may come from another dependency installed vianpm 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./usr/lib/node_modulesand/usr/local/lib/node_modulesfolders and remove themnode+npmnode_modulesviapacman. Or try and move the modules folders back one by one to test which one causes the errorantonis-tsolomitis commentedon Feb 11, 2024
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:
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 commentedon 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 commentedon Feb 11, 2024
It may be that they are no longer required by recent versions of
node- I'm on the latest version and mynode_modulesdoesn't seem to contain those folders any longer.antonis-tsolomitis commentedon Feb 11, 2024
OK. Great!
devsnd commentedon 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_modulesthat were part of the npm install, so to fix it on arch I did:Note: This obviously nukes your globally installed node_modules, but I wanted a clean state to work off of
sarthakgupta898 commentedon Apr 24, 2024
What is the workaround for windows?
AlonaAkimova commentedon 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:
Yarn:
Hope it helps.