npm / cli

the package manager for JavaScript

Home Page:https://docs.npmjs.com/cli/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] `install` and `cache add` disagrees on accept header

hundeboll opened this issue · comments

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.