cli
cli copied to clipboard
[BUG] Installing with --prefer-offline does not work if dependencies are not available in the cache
Is there an existing issue for this?
- [X] I have searched the existing issues
This issue exists in the latest npm version
- [X] I am using the latest npm
Current Behavior
% npm i --prefer-offline
npm ERR! code ETARGET
npm ERR! notarget No matching version found for @vaadin/[email protected].
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
Expected Behavior
It should fetch the missing version from npmjs.com, like npm i
does. That is the whole point of using --prefer-offline
offline instead of --offline
Steps To Reproduce
Using
{
"name": "no-name",
"license": "UNLICENSED",
"type": "module",
"dependencies": {
"@vaadin/scroller": "24.1.0-alpha8"
}
}
run npm i --prefer-offline
Environment
- npm: 9.5.1
- Node.js: v18.16.0
- OS Name: macOs Ventura
- System Model Name: Mac M1
- npm config:
ignore-scripts = true
This happened to me too with @webassemblyjs/helper-numbers package and node 16.20. I had to npm install
without --prefer-offline
to make it work. It should be "prefer" not "force" ;)
I am having this issue using npm v9.8.1
and it gets solved by running npm cache clean --force
, I am also using prefer-offline
Experiencing this on Node v20.10.0
and npm v10.3.0
. macOS Ventura on an M1 Pro Mac.
Manually running without --prefer-offline
or running npm i
for the explicit missing package and version adds it to the cache. The following npm ci --prefer-offline
is successful.
I believe my Windows-using counterparts are experiencing this as well, though I have been unable to confirm that at this time.
I was able to reproduce the issue in my GitLab CI (and this is a big problem because it is an automated environment while all the solutions above require manual intervention) and the logfile with the project name replaced with <redacted>
is below.
Command: npm install --ignore-scripts --no-audit --no-fund
Env: NPM_CONFIG_CACHE=.cache/npm
; NPM_CONFIG_PREFER_OFFLINE=true
npm logfile (click to expand)
0 verbose cli /usr/local/bin/node /usr/local/bin/npm
1 info using [email protected]
2 info using [email protected]
3 timing npm:load:whichnode Completed in 4ms
4 timing config:load:defaults Completed in 3ms
5 timing config:load:file:/usr/local/lib/node_modules/npm/npmrc Completed in 4ms
6 timing config:load:builtin Completed in 5ms
7 timing config:load:cli Completed in 8ms
8 timing config:load:env Completed in 3ms
9 timing config:load:file:/builds/rdnxk/<redacted>.npmrc Completed in 5ms
10 timing config:load:project Completed in 7ms
11 timing config:load:file:/root/.npmrc Completed in 0ms
12 timing config:load:user Completed in 0ms
13 timing config:load:file:/usr/local/etc/npmrc Completed in 1ms
14 timing config:load:global Completed in 1ms
15 timing config:load:setEnvs Completed in 1ms
16 timing config:load Completed in 29ms
17 timing npm:load:configload Completed in 29ms
18 timing config:load:flatten Completed in 4ms
19 timing npm:load:mkdirpcache Completed in 7ms
20 timing npm:load:mkdirplogs Completed in 3ms
21 verbose title npm install
22 verbose argv "install" "--ignore-scripts" "--no-audit" "--no-fund"
23 timing npm:load:setTitle Completed in 2ms
24 timing npm:load:display Completed in 1ms
25 verbose logfile logs-max:10 dir:/builds/rdnxk/<redacted>/.cache/npm/_logs/2024-04-03T22_38_45_672Z-
26 verbose logfile /builds/rdnxk/<redacted>/.cache/npm/_logs/2024-04-03T22_38_45_672Z-debug-0.log
27 timing npm:load:logFile Completed in 14ms
28 timing npm:load:timers Completed in 0ms
29 timing npm:load:configScope Completed in 0ms
30 timing npm:load Completed in 86ms
31 timing arborist:ctor Completed in 1ms
32 silly logfile done cleaning log files
33 timing arborist:ctor Completed in 0ms
34 timing idealTree:init Completed in 27ms
35 timing idealTree:userRequests Completed in 1ms
36 silly idealTree buildDeps
37 silly fetch manifest @jenniferplusplus/opentelemetry-instrumentation-bullmq@^0.5.0
38 http fetch GET 200 https://registry.npmjs.org/@jenniferplusplus%2fopentelemetry-instrumentation-bullmq 24ms (cache stale)
39 silly fetch manifest bullmq@^5.5.1
40 http fetch GET 200 https://registry.npmjs.org/bullmq 13ms (cache stale)
41 silly fetch manifest bullmq@^2 || ^3 || ^4 || ^5
42 timing idealTree Completed in 121ms
43 timing command:install Completed in 133ms
44 verbose stack Error: unable to resolve dependency tree
44 verbose stack at #failPeerConflict (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:1387:25)
44 verbose stack at #loadPeerSet (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:1353:33)
44 verbose stack at async #buildDepStep (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:924:11)
44 verbose stack at async Arborist.buildIdealTree (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:203:7)
44 verbose stack at async Promise.all (index 1)
44 verbose stack at async Arborist.reify (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:154:5)
44 verbose stack at async Install.exec (/usr/local/lib/node_modules/npm/lib/commands/install.js:153:5)
44 verbose stack at async module.exports (/usr/local/lib/node_modules/npm/lib/cli-entry.js:61:5)
45 verbose cwd /builds/rdnxk/<redacted>
46 verbose Linux 5.15.0-101-generic
47 verbose node v20.12.0
48 verbose npm v10.5.0
49 error code ERESOLVE
50 error ERESOLVE unable to resolve dependency tree
51 error
52 error While resolving: <redacted>@0.1.0
52 error Found: bullmq@undefined
52 error node_modules/bullmq
52 error bullmq@"^5.5.1" from the root project
52 error
52 error Could not resolve dependency:
52 error peer bullmq@"^2 || ^3 || ^4 || ^5" from @jenniferplusplus/[email protected]
52 error node_modules/@jenniferplusplus/opentelemetry-instrumentation-bullmq
52 error @jenniferplusplus/opentelemetry-instrumentation-bullmq@"^0.5.0" from the root project
52 error
52 error Fix the upstream dependency conflict, or retry
52 error this command with --force or --legacy-peer-deps
52 error to accept an incorrect (and potentially broken) dependency resolution.
53 error
53 error
53 error For a full report see:
53 error /builds/rdnxk/<redacted>/.cache/npm/_logs/2024-04-03T22_38_45_672Z-eresolve-report.txt
54 verbose exit 1
55 timing npm Completed in 510ms
56 verbose unfinished npm timer reify 1712183926045
57 verbose unfinished npm timer reify:loadTrees 1712183926052
58 verbose unfinished npm timer idealTree:buildDeps 1712183926081
59 verbose unfinished npm timer idealTree:#root 1712183926081
60 verbose code 1
61 error A complete log of this run can be found in: /builds/rdnxk/<redacted>/.cache/npm/_logs/2024-04-03T22_38_45_672Z-debug-0.log
The npm script wanted [email protected]
, but this version was not available in cache but the version 5.5.0
was, causing it to fail.
My temp solution was just to stop using the prefer-offline config, but this increased the install time from 31s to 4m