FS#79693 - [npm] Broken executable (TypeError: LRU is not a constructor)
Attached to Project:
Arch Linux
Opened by Fabio (blacklight) - Thursday, 14 September 2023, 22:32 GMT
Last edited by Toolybird (Toolybird) - Thursday, 14 September 2023, 23:50 GMT
Opened by Fabio (blacklight) - Thursday, 14 September 2023, 22:32 GMT
Last edited by Toolybird (Toolybird) - Thursday, 14 September 2023, 23:50 GMT
|
Details
Description:
The most recent version of npm breaks when executed, regardless of the command Additional info: * package version(s): Tested on 10.1.0, downgrading to 9.8.1 fixes the problem * config and/or log files etc.: N/A * link to upstream bug report, if any: https://github.com/npm/cli/issues/6785 Steps to reproduce: ``` $ 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) ``` |
This task depends upon
Closed by Toolybird (Toolybird)
Thursday, 14 September 2023, 23:50 GMT
Reason for closing: Not a bug
Additional comments about closing: See comments
Thursday, 14 September 2023, 23:50 GMT
Reason for closing: Not a bug
Additional comments about closing: See comments
Rookie error [1].
https://wiki.archlinux.org/title/Bug_reporting_guidelines#Severity
However I don't think that "low" is the right level here either.
If "high" applies to "The main functionality of the application does not work", and typing "npm" causes a stack trace, then I guess that that should be the right severity here?
Anyway, the issue doesn't repro for me. Just installed npm inside fresh clean VM and no problem:
$ npm --version
10.1.0
There must something else going on?
That's quite likely the case. And I think that I have also identified a likely culprit.
I've given it a try on a few more machines in the meantime. Mileage varies - it reproduces on some, it doesn't on others.
At a closer look of the stack trace:
```
TypeError: LRU is not a constructor
at Object.<anonymous> (/usr/lib/node_modules/npm/node_modules/semver/classes/range.js:188:15)
```
The error is thrown within the `semver` module installed under the system `node_modules` directory - this seems to be the case also for the original reporter of the Github issue.
I've noticed that the bug reproduces on systems where `/usr/lib/node_modules/npm/node_modules/semver` is present.
It can be fixed by:
1. pacman -R npm semver <...anything that depends on npm...>
2. rm -rf /usr/lib/node_modules/npm/node_modules/semver
3. pacman -S npm semver <...>
The fact that `semver` was installed under `/usr/lib/node_modules/npm/node_modules/semver` and not `/usr/lib/node_modules/semver` means that somebody else put an old version there, which may be:
1. An older version of the semver package itself
2. Some packages installed via e.g. `npm install -g`
Maybe something worth documenting in the FAQ/Troubleshooting in case someone else bumps into the issue on upgrade?
Good point @loqs. But just tested with the other versions (16.x, 18.x) and all still fine. Though of course 16.x emits a warning:
$ npm --version
npm WARN cli npm v10.1.0 does not support Node.js v16.20.2. This version of npm supports the following node versions: `^18.17.0 || >=20.5.0`. You can find the latest version at https://nodejs.org/.
10.1.0
> /usr/lib/node_modules/npm/node_modules/semver/classes/range.js
That path doesn't exist so it appears something is amiss with @reporter's system.