pnpm: "ERR_INVALID_THIS" on "pnpm up" in Node 20

pnpm version: 8.3.0

Code to reproduce the issue:

In a pnpm project, install, then run pnpm up.

An easy repro is just to try it in the pnpm repo itself.

Expected behavior:

No error

Actual behavior:

 WARN  GET https://registry.npmjs.org/@definitelytyped%2Fdefinitions-parser error (ERR_INVALID_THIS). Will retry in 10 seconds. 2 retries left.
 WARN  GET https://registry.npmjs.org/@definitelytyped%2Fdtslint-runner error (ERR_INVALID_THIS). Will retry in 10 seconds. 2 retries left.
 WARN  GET https://registry.npmjs.org/@definitelytyped%2Fheader-parser error (ERR_INVALID_THIS). Will retry in 10 seconds. 2 retries left.
 WARN  GET https://registry.npmjs.org/@definitelytyped%2Ftypescript-versions error (ERR_INVALID_THIS). Will retry in 10 seconds. 2 retries left.
 WARN  GET https://registry.npmjs.org/@definitelytyped%2Futils error (ERR_INVALID_THIS). Will retry in 10 seconds. 2 retries left.
 WARN  GET https://registry.npmjs.org/typescript error (ERR_INVALID_THIS). Will retry in 10 seconds. 2 retries left.
 WARN  GET https://registry.npmjs.org/@definitelytyped%2Fdtslint error (ERR_INVALID_THIS). Will retry in 10 seconds. 2 retries left.
 WARN  GET https://registry.npmjs.org/@octokit%2Fcore error (ERR_INVALID_THIS). Will retry in 10 seconds. 2 retries left.
 WARN  GET https://registry.npmjs.org/@octokit%2Frest error (ERR_INVALID_THIS). Will retry in 10 seconds. 2 retries left.
 WARN  GET https://registry.npmjs.org/comment-json error (ERR_INVALID_THIS). Will retry in 10 seconds. 2 retries left.
 WARN  GET https://registry.npmjs.org/d3-array error (ERR_INVALID_THIS). Will retry in 10 seconds. 2 retries left.
 WARN  GET https://registry.npmjs.org/d3-axis error (ERR_INVALID_THIS). Will retry in 10 seconds. 2 retries left.
 WARN  GET https://registry.npmjs.org/d3-scale error (ERR_INVALID_THIS). Will retry in 10 seconds. 2 retries left.
 WARN  GET https://registry.npmjs.org/d3-selection error (ERR_INVALID_THIS). Will retry in 10 seconds. 2 retries left.
 WARN  GET https://registry.npmjs.org/d3-time error (ERR_INVALID_THIS). Will retry in 10 seconds. 2 retries left.
 WARN  GET https://registry.npmjs.org/d3-time-format error (ERR_INVALID_THIS). Will retry in 10 seconds. 2 retries left.

Additional information:

  • node -v prints: v20.0.0
  • Windows, macOS, or Linux?: Linux

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 62
  • Comments: 64 (22 by maintainers)

Commits related to this issue

Most upvoted comments

To help anyone else using pnpm globally installed by pnpm:

npx pnpm i -g pnpm@latest

Fixed in v8.3.1

In my case pnpm works fine with previous node version (v19.8.1).

Only when I try to use node v20, it throws (ERR_INVALID_THIS)

 WARN  GET https://registry.npmjs.org/create-t3-app error (ERR_INVALID_THIS). Will retry in 10 seconds. 2 retries left.

I use NVM to change to switch.

corepack prepare pnpm@8.3.1 --activate did the trick for me, on mac.

pnpm was installed with the node/corepack brew package so i didn’t want to use npx as mentioned above (https://github.com/pnpm/pnpm/issues/6424#issuecomment-1515748464).

There are other issues like this, it seems:

pnpm install
Scope: all 142 workspace projects
 ERR_PNPM_META_FETCH_FAIL  GET https://registry.npmjs.org/pnpm: Value of "this" must be of type URLSearchParams
Lockfile is up to date, resolution step is skipped

Still happening, with pnpm v8.15.3 and node v20.11.0

Still happening for me with pnpm v8.14.0 and node v20.10.0

Can confirm this only seems to happen on the latest node 20 and using a previous version (19.9.0 in my case) it works fine.

Getting: ERR_INVALID_THIS as well as:  ERR_PNPM_META_FETCH_FAIL  GET https://registry.npmjs.org/packagename: Value of "this" must be of type URLSearchParams

I’m still getting this error when deploying to my Render.com instance with Node 20 enabled.

Even using corepack does not solve the issue.

This should definitely not be closed

To me a newer version of pnpm helped. I had to install it using npm install -g pnpm --force if I recall correctly. I had to use force because else there was some error which I of course did not read but the error suggested using force so I did. May the --force be with you!

This doesn’t appear to be fully fixed unless I’m missing something- I’'m running on a Mac and have updated to the latest but it still persists. – hold that thought, IntelliJ is giving me a different version than outside. Probably my issue. UPDATE: fixed. The version pulled by npx is not up to date. On a Mac I had to upgrade via home-brew and use it to override symlinks.

Very strange… in my case nothing worked for me until I used:

yarn global add pnpm@latest

We’ll switch to a fork of node-fetch with a fix. Here’s the fix: pnpm/node-fetch#1

why don’t you use native ‘fetch’? So wouldn’t you be avoiding problems like this in the future?

Still happen with pnpm 9.0.6 and node v20.11.1

You can use corepack up to update your pnpm version and packageManager in package.json in one step.

I’m finding this issue on Apple M2 Pro while using nektos/act with pnpm 8.10.0 and node v20.9.0

To help anyone else using pnpm globally installed by pnpm:

npx pnpm i -g pnpm@latest

 ERR_PNPM_META_FETCH_FAIL  GET https://registry.npmjs.org/pnpm: Value of "this" must be of type URLSearchParams Is it just me?

Its probably executing pnpm from cache causing the same issue. npx pnpm@latest i -g pnpm@latest should do the trick. Or just install npm i -g pnpm@latest directly.

I updated to node v20 last night using

pnpm env use --global 20

and faced similar issues but the problem is now I cannot even go back to node v19 or v18

pnpm env use --global 19

gives

 WARN  GET https://nodejs.org/download/release/index.json error (ERR_INVALID_THIS). Will retry in 10 seconds. 2 retries left.
 WARN  GET https://nodejs.org/download/release/index.json error (ERR_INVALID_THIS). Will retry in 1 minute. 1 retries left.
 ERR_INVALID_THIS  Value of "this" must be of type URLSearchParams

pnpm [ERR_INVALID_THIS]: Value of "this" must be of type URLSearchParams
    at new NodeError (node:internal/errors:399:5)
    at Proxy.getAll (node:internal/url:482:13)
    at Proxy.<anonymous> (/usr/local/Cellar/pnpm/8.3.0/libexec/dist/pnpm.cjs:60672:55)
    at /usr/local/Cellar/pnpm/8.3.0/libexec/dist/pnpm.cjs:60734:31
    at Array.reduce (<anonymous>)
    at Proxy.raw (/usr/local/Cellar/pnpm/8.3.0/libexec/dist/pnpm.cjs:60733:33)
    at new Headers (/usr/local/Cellar/pnpm/8.3.0/libexec/dist/pnpm.cjs:60618:28)
    at getNodeRequestOptions (/usr/local/Cellar/pnpm/8.3.0/libexec/dist/pnpm.cjs:60967:23)
    at /usr/local/Cellar/pnpm/8.3.0/libexec/dist/pnpm.cjs:61024:25
    at new Promise (<anonymous>)

I get it when using pnpm install on node version 21 and I’m using pnpm version 8.8.0.

 WARN  GET https://registry.npmjs.org/@radix-ui%2Freact-icons error (ERR_INVALID_THIS). Will retry in 10 seconds. 2 retries left.
 WARN  GET https://registry.npmjs.org/@radix-ui%2Freact-radio-group error (ERR_INVALID_THIS). Will retry in 10 seconds. 2 retries left.
| Progress: resolved 0, reused 1, downl../..                                    
| Progress: resolved 23, reused 23, dow../..                                    
| Progress: resolved 29, reused 29, dow../..
| Progress: resolved 30, reused 30, dow WARN  GET https://registry.npmjs.org/@radix-ui%2Freact-icons error (ERR_INVALID_THIS). Will retry in 1 minute. 1 retries left.
| Progress: resolved 30, reused 30, dow WARN  GET https://registry.npmjs.org/@radix-ui%2Freact-radio-group error (ERR_INVALID_THIS). Will retry in 1 minute. 1 retries left.
| Progress: resolved 30, reused 30, downloaded 0, added 0

This issue does happen inside github actions when using act to run them locally. Annoying…

even with standalone script installation via the action

For those who have the same problem just revert your node installation to v18.17.0

hi, why don’t you use native ‘fetch’? So wouldn’t you be avoiding problems like this in the future?

native fetch is not present in node.js v16. And even in node.js v18 it is experimental. So, we cannot use it.

We’ll switch to a fork of node-fetch with a fix. Here’s the fix: https://github.com/pnpm/node-fetch/pull/1

The logs show that you’re running pnpm 7.15, which is much too old for this issue to have been fixed. You need to upgrade to at least 7.32.2 or 8.3.1.

I’m on a mac M1, using corepack (node v20.10.0, pnpm v8.14.1) and the following rectified the issue for me corepack prepare pnpm@latest --activate

Hope it helps someone.

The stack trace shows that you’re still using 8.1.1, and the fix for this was only introduced in 8.3.1.

See: https://github.com/mswjs/cookies/actions/runs/6798894268/job/18483965198?pr=29#step:4:18

This is because your workflow says version: 8.10, which YAML reads as being the same value as 8.1 as it’s parsed as a number. Quoting the string, making it 8.10.1, or not setting the version in the workflow (e.g. use corepack) will all fix this.

switching to node v18 LTS is working fine. Error with v20.5.0.

nvm install v18.17.1
pnpm add vue-tippy@v6