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] Cannot read property 'pickAlgorithm' of null #5496

Open
DetachHead opened this issue Sep 13, 2022 · 13 comments
Open

[BUG] Cannot read property 'pickAlgorithm' of null #5496

DetachHead opened this issue Sep 13, 2022 · 13 comments
Labels
Bug thing that needs fixing Priority 1 high priority issue

Comments

@DetachHead
Copy link

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
@ljharb
Copy link
Collaborator

ljharb commented Sep 13, 2022

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

@OmgImAlexis
Copy link

Same issue here on npm@8.11.0.

@ljharb
Copy link
Collaborator

ljharb commented Sep 13, 2022

and on v8.19.1?

@OmgImAlexis
Copy link

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
Copy link

Related npm/ssri#27

@OmgImAlexis
Copy link

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

#3374 (comment)

@ahmedwelhakim
Copy link

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.

@tomleader
Copy link

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

@Rajesh01-star
Copy link

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

@Cactusbone
Copy link

Cactusbone commented Oct 24, 2022

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 #5278 (comment)) made the issue disappear.

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

@lukekarrys lukekarrys added Bug thing that needs fixing Priority 1 high priority issue labels Oct 27, 2022
@lukekarrys lukekarrys self-assigned this Oct 27, 2022
@lukekarrys lukekarrys removed their assignment Nov 12, 2022
@youngfreeFJS
Copy link

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

worked for me!

@stephanpieterse
Copy link

stephanpieterse commented Jan 31, 2024

We are facing a similar issue installing aws-cdk@latest (resolves to v2.124.0)

node v18.13.0 (with npm 8.19.3) - breaks with Cannot read properties of null (reading 'pickAlgorithm')
node v20.3.1 (with npm 9.6.7) - works as expected

A colleague has tested with node v18.13.0 (with npm 9.8.1) and it also works as expected.

With npm 8.19.3, specifically installing aws-cdk@2.122 works as well.

Interestingly, installing v2.122 and THEN v.2.124.0 seems to solve whatever issue there is with installing v2.124 from a 'clean' slate.

[30 min later]

I was able to reproduce it reliably with the aws-cdk versions, but now it seems to happen sporadically.
Below is a list of the other dependencies in the project which might be related, in our specific case we are able to use npm v9 and aws-cdk at a specific verison so we have a stable solution.

  "dependencies": {
    "aws-cdk-lib": "^2.114.1",
    "constructs": "^10.3.0",
    "source-map-support": "^0.5.21"
  },
  "devDependencies": {
    "@types/aws-lambda": "^8.10.129",
    "@types/jest": "^29.5.4",
    "@types/node": "20.5.7",
    "@typescript-eslint/eslint-plugin": "^6.18.1",
    "@typescript-eslint/parser": "^6.18.1",
    "aws-cdk": "^2.124.0",
    "esbuild": "^0.20.0",
    "eslint": "^8.56.0",
    "eslint-plugin-import": "^2.29.1",
    "eslint-plugin-jsdoc": "^48.0.2",
    "jest": "^29.6.4",
    "open-cli": "^7.2.0",
    "pre-commit": "^1.2.2",
    "ts-jest": "^29.1.1",
    "ts-node": "^10.9.1",
    "typedoc": "^0.25.4",
    "typescript": "~5.2.2"
  },

--- UPDATE ---
Turns out there was a reference in the package-lock.json to a http repository instead of https that (probably) snuck in from someones local configuration. Recreating it with the https URLs fixed the issue on npm v8.

@Tellys
Copy link

Tellys commented Feb 3, 2024

The article below answered your question well. Pickalgorithm npm error

https://www.conteudopertinente.com.br/npm/pickalgorithm-npm-error/

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 1 high priority issue
Projects
None yet
Development

No branches or pull requests