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 4 years ago
  • Reactions: 66
  • Comments: 82 (26 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

Updating pnpm/action-setup to v4 solved the issue for me ✅

Seeing this in a CLI environment after zero changes between yesterday and today.

Screenshot 2024-07-03 at 8 18 04 PM

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

I was able to fix this by bumping the action and the pnpm version

Screenshot 2024-07-03 at 8 44 08 PM

Still happening, with pnpm v8.15.3 and node v20.11.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

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

I’m also facing this issue. Screenshot 2024-07-04 at 06 00 11

Restarting terminal fixed the issue

Still happen with pnpm 9.0.6 and node v20.11.1

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.

Updating pnpm/action-setup to v4 worked for me as well.

This should definitely not be closed

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.

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!

Would love to know how this is suddenly happening for so many people.

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

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?

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’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.

@Johnnasimba

there is a solution literally one comment before yours.

I’m facing the same issue, has anyone found a solution yet Screenshot 2024-07-04 at 12 47 32

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.

My problem was that I was using the pnpm provided via homebrew.

Check via:

which pnpm

If it is /opt/homebrew/bin/pnpm uninstall via brew uninstall pnpm and install via npx pnpm i -g pnpm@latest

This bug is most certainly fixed. You should verify that you’re actually using that pnpm version and that something is not being overridden in your environment, e.g. by corepack or similar.

FWIW, as a first time user of pnpm, I experienced this issue and believe it’s still an unfixed bug.

I followed a link to the pnpm installation page to install pnpm. The first few lines of the installation page do not make it clear that using the standalone script is the preferred way to install pnpm. I read those lines as saying that I “could” use the standalone script if I’m on an older version of Node.js, however, I can use native Node.js features like corepack or npm to install pnpm.

I choose to use corepack since all I had to do was this:

corepack enable pnpm

Then I run pnpm i in the project that I’m attempting to set up and I get the ERR_INVALID_THIS over and over.

I find this issue and check my pnpm version and see that corepack has installed an old version by default, so I followed instructions to update the version. After updating the version of pnpm, I continued to get the same ERR_INVALID_THIS. I switched to node v18.18.0 and the issue went away.

I switched back to node v21.6.0, “disabled” pnpm by running corepack disable pnpm, then installed pnpm using the standalone script.

Since at one point, I used corepack to update pnpm to the latest, and that didn’t work, I consider this to still be a bug.

Of course, now that I got to a point where pnpm i works, I’m running into another issue that I believe may be a core Node.js issue detecting the cpu arch since pnpm seems to have installed the correct optional dependency (@rollup/rollup-darwin-arm64), but the library (rollup) thinks it should be @rollup/rollup-darwin-x64.

/edit: I figured out my issue in case anyone is interested… I had installed node via nvm when I was running in an iTerm session that had been opened using Rosetta to emulate an x64 on the Apple arm chips. After re-installing node, in a session opened without Rosetta, node reports arm64, which allows rollup to resolve the correct dependency.

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