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] install and cache add disagrees on accept header #7465

Closed
2 tasks done
hundeboll opened this issue May 3, 2024 · 0 comments · Fixed by #7516
Closed
2 tasks done

[BUG] install and cache add disagrees on accept header #7465

hundeboll opened this issue May 3, 2024 · 0 comments · Fixed by #7516
Assignees
Labels
Bug thing that needs fixing Priority 2 secondary priority issue

Comments

@hundeboll
Copy link

hundeboll commented May 3, 2024

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

Offline installs fails with ENOTCACHED after caching dependencies using npm cache add <dep>:

% npm --cache /tmp/cache cache add nan
npm notice 
npm notice New minor version of npm available! 10.5.1 -> 10.7.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.7.0
npm notice Run npm install -g npm@10.7.0 to update!
npm notice 

% npm --cache /tmp/cache --offline install nan
npm ERR! code ENOTCACHED
npm ERR! request to https://registry.npmjs.org/nan failed: cache mode is 'only-if-cached' but no cached response is available.

npm ERR! A complete log of this run can be found in: /tmp/cache/_logs/2024-05-03T09_19_30_468Z-debug-0.log

Expected Behavior

% npm --cache /tmp/cache cache add nan
% npm --cache /tmp/cache --offline install nan

added 1 package, and audited 2 packages in 261ms

found 0 vulnerabilities

Steps To Reproduce

As above:

npm --cache /tmp/cache add nan
npn --cache /tmp/cache --offline install nan

Findings

By comparing the output of

cacache.ls("/tmp/cache/_cacache").then(console.log)

from populating the cache with first npm install and then with npm cache add I found that the accept: header is different:

npm install: accept: 'application/json'
npm cache add: accept: 'application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*'

Environment

  • npm: 10.5.1
  • Node.js: v21.7.2
  • OS Name: Arch Linux
  • System Model Name: Lenovo T14s
  • npm config:
; node bin location = /usr/bin/node
; node version = v21.7.2
; npm local prefix = /tmp/scratch
; npm version = 10.5.1
; cwd = /tmp/scratch
; HOME = /nas/home/martin
; Run `npm config ls -l` to show all defaults.
@hundeboll hundeboll added Bug thing that needs fixing Needs Triage needs review for next steps Release 10.x labels May 3, 2024
@milaninfy milaninfy added Priority 2 secondary priority issue Needs Triage needs review for next steps and removed Needs Triage needs review for next steps Priority 2 secondary priority issue labels May 3, 2024
kraj pushed a commit to YoeDistro/meta-openembedded that referenced this issue May 3, 2024
Apparently, npm has changed its request accept header, so that cache
lookup misses. This causes an ENOTCACHED error when doing the offline
install in do_compile() from npm.bbclass.

Fix it by updating the fake cache entry to match the newest behaviour
from npm.

Note that npm doesn't agree with itself, as it still uses the previous
header value when doing `npm cache add <pkg>`, but the new value when
doing `npm install <pkg>`.

Bug submitted upstream:
npm/cli#7465

Signed-off-by: Martin Hundebøll <martin@geanix.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
@wraithgar wraithgar added Priority 2 secondary priority issue and removed Needs Triage needs review for next steps labels May 3, 2024
@milaninfy milaninfy self-assigned this May 10, 2024
daregit pushed a commit to daregit/yocto-combined that referenced this issue May 22, 2024
…ncies

Apparently, npm has changed its request accept header, so that cache
lookup misses. This causes an ENOTCACHED error when doing the offline
install in do_compile() from npm.bbclass.

Fix it by updating the fake cache entry to match the newest behaviour
from npm.

Note that npm doesn't agree with itself, as it still uses the previous
header value when doing `npm cache add <pkg>`, but the new value when
doing `npm install <pkg>`.

Bug submitted upstream:
npm/cli#7465

Signed-off-by: Martin Hundebøll <martin@geanix.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
wraithgar pushed a commit that referenced this issue May 22, 2024
This will fix the `npm cache add` to cache package with same header as
it's used in `npm install` by adding extra manifest call with
`fullMetadata: true` while caching to match behaviour with install
command which internally request manifest with fullMetadata.

## References
Closes #7465
halstead pushed a commit to openembedded/meta-openembedded that referenced this issue May 22, 2024
Apparently, npm has changed its request accept header, so that cache
lookup misses. This causes an ENOTCACHED error when doing the offline
install in do_compile() from npm.bbclass.

Fix it by updating the fake cache entry to match the newest behaviour
from npm.

Note that npm doesn't agree with itself, as it still uses the previous
header value when doing `npm cache add <pkg>`, but the new value when
doing `npm install <pkg>`.

Bug submitted upstream:
npm/cli#7465

Signed-off-by: Martin Hundebøll <martin@geanix.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Priority 2 secondary priority issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants