cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] Cannot read property 'pickAlgorithm' of null

Open DetachHead opened this issue 1 year ago • 13 comments

re-raising #3374 as it was closed without a proper solution.

for many users this occurs on every npm install, meaning we have to run npm cache clean --force every time.

Is there an existing issue for this?

* [x]  I have searched the existing issues

Current Behavior

Whenever typing an npx function, I receive an error. It seems that NPM, itself, is broken on my device.

When typing npx create-react-app testing in my terminal, I receive the following error: Invalid response body while trying to fetch https://registry.npmjs.org/create-react-app: Cannot read property 'pickAlgorithm' of null

Which produces the below error log: 2021-06-06T03_09_42_989Z-debug.log

Expected Behavior

I was not expecting an error to occur. I was expecting an application to be created.

Steps To Reproduce

1. In this environment...
   I am on Ubuntu and typing into my terminal. I was attempting to install jest for testing in a react project, and I accidentally typed "npm install --save-dev jes" instead (notice the missing t). I aborted that command a few seconds after my terminal started logging changes, and my npm has been broken since.

2. With this config...
   This problem isn't specific to any project - it is an issue across my entire directory.

3. Run '...'
   As stated, I originally ran  "npm install --save-dev jes".

Afterwards, when I tried creating the testing application, which resulted in my terminal spewing countless lines of errors before telling me that I should log this issue.

I then tried to create my testing application again, but this time I received an error stating I don't have enough space on my device, which made me think that the prior error consumed space on my device. I checked my storage with df -h, and I saw that my /dev/sdal, /dev/loop0, and /dev/loop1 folders were all full. I cleared my trash folder, and then I ran npm cache clean --force to try and lower the storage, but only /dev/sdal went down (and only to 90%).

4. See error...
   Now when I try to create my testing application, the error I see is as the one in my Current Behavior description.
   Invalid response body while trying to fetch https://registry.npmjs.org/create-react-app: Cannot read property 'pickAlgorithm' of null

Environment

* OS: Ubuntu 20.04

* Node: v14.1.0

* npm: 7.16.0

DetachHead avatar Sep 13 '22 06:09 DetachHead

npm 7 is long EOL. Can you try npm 8 latest?

ljharb avatar Sep 13 '22 06:09 ljharb

Same issue here on [email protected].

OmgImAlexis avatar Sep 13 '22 06:09 OmgImAlexis

and on v8.19.1?

ljharb avatar Sep 13 '22 06:09 ljharb

Yep, did npm i -g npm@latest and got the same version you mentioned. Also the log file it mentions doesn't exist.

npm ERR! code 1
npm ERR! git dep preparation failed
npm ERR! command C:\Program Files\nodejs\node.exe C:\Users\xo\AppData\Roaming\nvm\v18.3.0\node_modules\npm\bin\npm-cli.js install --force --cache=C:\Users\xo\AppData\Local\npm-cache --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit --include=dev --include=peer --include=optional --no-package-lock-only --no-dry-run
npm ERR! npm WARN using --force Recommended protections disabled.
npm ERR! npm ERR! Cannot read properties of null (reading 'pickAlgorithm')
npm ERR!
npm ERR! npm ERR! A complete log of this run can be found in:
npm ERR! npm ERR!     C:\Users\xo\AppData\Local\npm-cache\_logs\2022-09-13T06_25_58_381Z-debug-0.log

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\xo\AppData\Local\npm-cache\_logs\2022-09-13T06_25_41_885Z-debug-0.log

OmgImAlexis avatar Sep 13 '22 06:09 OmgImAlexis

Related https://github.com/npm/ssri/issues/27

OmgImAlexis avatar Sep 13 '22 06:09 OmgImAlexis

@DetachHead if you need a work around I can confirm my install is now working after adding this patch.

https://github.com/npm/cli/issues/3374#issuecomment-1140963562

OmgImAlexis avatar Sep 13 '22 06:09 OmgImAlexis

I have the same error and clearing the cache is not working. So I tried npm install [THE_LIBRARY] --verbose

TypeError: Cannot read properties of null (reading 'pickAlgorithm')
npm verb stack     at Integrity.match (/usr/lib/node_modules/npm/node_modules/ssri/lib/index.js:273:24)
npm verb stack     at CachePolicy.satisfies (/usr/lib/node_modules/npm/node_modules/make-fetch-happen/lib/cache/policy.js:112:49)
npm verb stack     at Function.find (/usr/lib/node_modules/npm/node_modules/make-fetch-happen/lib/cache/entry.js:178:25)
npm verb stack     at async cacheFetch (/usr/lib/node_modules/npm/node_modules/make-fetch-happen/lib/cache/index.js:8:17)
npm verb stack     at async fetch (/usr/lib/node_modules/npm/node_modules/make-fetch-happen/lib/fetch.js:98:7)

so from the log It's obvious that the error is At Integrity.match at line 273 in /usr/lib/node_modules/npm/node_modules/ssri/lib/index.js , which is due to other = null and the code try to access a field.
So an easy solution is to use optional chaining opertator '?' so we change: const algo = other.pickAlgorithm(opts) to const algo = other?.pickAlgorithm(opts)

  match (integrity, opts) {
    opts = ssriOpts(opts)
    const other = parse(integrity, opts)
    const algo = other?.pickAlgorithm(opts)
    return (
      this[algo] &&
      other[algo] &&
      this[algo].find(hash =>
        other[algo].find(otherhash =>
          hash.digest === otherhash.digest
        )
      )
    ) || false
  }

Actually this bug happens many times for no specific reason. And there is a thread at stackoverflow from 11 monthes with npm: 7.21.0 and Node: 14.17.4

I'm using node: 16.17.0, npm: 8.19.1 and I face the same problem. So I hope this bug to be fixed soon.

ahmedwelhakim avatar Sep 13 '22 21:09 ahmedwelhakim

npm 8.19.2 still face the same problem. And clear cache is NOT working.

tomleader avatar Oct 09 '22 08:10 tomleader

npm uninstall -g create-react-app; npm cache clear --force; npm install;npx create-react-app myapp`` worked for me

Rajesh01-star avatar Oct 10 '22 13:10 Rajesh01-star

I'm having this issue with Node.js v18.11.0 and npm 8.19.2 (also with v16.18.0 and npm 8.19.2), however it sometimes works on npm 8.15.1 with Node.js v16.18.0.

I'm having the issue on my CI, so I reproduce it quite often...

Removing the only dependency using git+ssh:// with only slashes (see https://github.com/npm/cli/issues/5278#issuecomment-1247380996) made the issue disappear.

Anyone else with this issue using git+ssh:// ?

Cactusbone avatar Oct 24 '22 16:10 Cactusbone