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

"ERR_INVALID_THIS" on "pnpm up" in Node 20 #6424

Closed
jakebailey opened this issue Apr 18, 2023 · 64 comments · Fixed by nuxt/module-builder#115 or vercel/next.js#51406
Closed

"ERR_INVALID_THIS" on "pnpm up" in Node 20 #6424

jakebailey opened this issue Apr 18, 2023 · 64 comments · Fixed by nuxt/module-builder#115 or vercel/next.js#51406

Comments

@jakebailey
Copy link
Member

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
@jakebailey
Copy link
Member Author

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

@jakebailey
Copy link
Member Author

The original issue seems to be thrown by node-fetch. I think that updating node-fetch should work?

neutron0831 added a commit to neutron0831/nlp100-ts that referenced this issue Apr 19, 2023
neutron0831 added a commit to neutron0831/nlp100-ts that referenced this issue Apr 19, 2023
@anurag-roy
Copy link

anurag-roy commented Apr 19, 2023

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>)

@KingBael09
Copy link

KingBael09 commented Apr 19, 2023

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.

kwaa added a commit to importantimport/a2 that referenced this issue Apr 19, 2023
@JouanDeag
Copy link

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

@gipo355
Copy link

gipo355 commented Apr 19, 2023

Confirm, same problem on updating to node 20 with asdf and pnpm 8.3.0

Stack trace on running pnpm install -r:

 WARN  GET https://registry.npmjs.org/@nrwl/eslint-plugin-nx/-/eslint-plugin-nx-15.9.2.tgz error (ERR_INVALID_THIS). Will retry in 10 seconds. 2 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> (/home/wol/.cache/node/corepack/pnpm/8.3.0/dist/pnpm.cjs:60672:55)
    at /home/wol/.cache/node/corepack/pnpm/8.3.0/dist/pnpm.cjs:60734:31
    at Array.reduce (<anonymous>)
    at Proxy.raw (/home/wol/.cache/node/corepack/pnpm/8.3.0/dist/pnpm.cjs:60733:33)
    at new Headers (/home/wol/.cache/node/corepack/pnpm/8.3.0/dist/pnpm.cjs:60618:28)
    at getNodeRequestOptions (/home/wol/.cache/node/corepack/pnpm/8.3.0/dist/pnpm.cjs:60967:23)
    at /home/wol/.cache/node/corepack/pnpm/8.3.0/dist/pnpm.cjs:61024:25
    at new Promise (<anonymous>)

when reverting to node 19 with asdf and pnpm 8.1 no problems occur

zkochan added a commit to pnpm/node-fetch that referenced this issue Apr 19, 2023
@zkochan
Copy link
Member

zkochan commented Apr 19, 2023

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

@zkochan
Copy link
Member

zkochan commented Apr 19, 2023

Fixed in v8.3.1

@zkochan zkochan closed this as completed Apr 19, 2023
@ekwoka
Copy link
Contributor

ekwoka commented Apr 20, 2023

To help anyone else using pnpm globally installed by pnpm:

npx pnpm i -g pnpm@latest

@marifcelik
Copy link

marifcelik commented Apr 22, 2023

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?

nickmccurdy added a commit to nickmccurdy/arktype that referenced this issue Apr 22, 2023
This patches node-fetch so pnpm install works on Node 20: pnpm/pnpm#6424
@rfilgas
Copy link

rfilgas commented Apr 24, 2023

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.

@zkochan
Copy link
Member

zkochan commented Apr 24, 2023

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.

@ekwoka
Copy link
Contributor

ekwoka commented Apr 24, 2023

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

On 18 it's not behind a flag, at least.

So we can make that PR in September when 16 is EOL?

@zkochan
Copy link
Member

zkochan commented Apr 24, 2023

It would be a breaking change. I don't know when the next major will be released.

@ammar-oker
Copy link

I'm still facing this issue with pnpm@8.14.2 and Node@20, it worked fine after downgrading to Node@18.

@jakebailey
Copy link
Member Author

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.

@ammar-oker
Copy link

@jakebailey yes, you're correct. it was getting overridden by corepack :)

liana-p added a commit to liana-p/narrat-engine that referenced this issue Jan 23, 2024
Getting this error on pnpm install with node 20... pnpm/pnpm#6424
liana-p added a commit to liana-p/narrat-engine that referenced this issue Jan 23, 2024
* fix: add pnpm install to IDE publish script (#213)

* fix: specific version of pnpm install

Getting this error on pnpm install with node 20... pnpm/pnpm#6424

* chore: update pnpm, update to node 20, remove ide narrat deps

* chore: trying to get the tauri action CI to find the right config

* chore: still trying to fix CI

* chore: ...

* chore: ...
sergeytimoshin added a commit to sergeytimoshin/mpl-bubblegum that referenced this issue Jan 26, 2024
pnpm 8.2.0 has issue which prevents to install dependencies:
“ WARN  GET https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz error (ERR_INVALID_THIS). Will retry in 1 minute. 1 retries left.”

See also: pnpm/pnpm#6424
@doowb
Copy link

doowb commented Feb 2, 2024

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.

@simlmx
Copy link

simlmx commented Feb 5, 2024

Don't forget to update the version in your package.json if it was set!

"packageManager": "pnpm@8.3.1"

@Bessonov
Copy link

Bessonov commented Feb 7, 2024

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

mogeko added a commit to mogeko/mogeko that referenced this issue Feb 11, 2024
PNPM (<= 8.3.1) is not compatible with Node.js 20

pnpm/pnpm#6424
@ekwoka
Copy link
Contributor

ekwoka commented Feb 12, 2024

This is still happening specifically when using act using node 20, either with an image with node20 or using node setup action before pnpm.

I know ACT isn't necessarily something pnpm has reason to specially investigate, but it seems something about docker, node20 and pnpm is an issue.

This is the case with the 9 alpha as well.

What I've mostly done is use node18 images, and have pnpm manage and use node20, but it's extremely strange.

Not even sure where an investigation would start, but just want whomever to know that this is an issue that exists, even if outside the scope of PNPM to resolve.

@Lenvia
Copy link

Lenvia commented Feb 14, 2024

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

@ryne-sunrun
Copy link

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

This fixed it for me! Thanks

@jercomio
Copy link

jercomio commented Mar 5, 2024

Hi,
I use Node v20 and I tried to use corepack up to update my pnpm version and packageManager in package.json . But it doesn't work for me, I've a same error.

This problem does not exist when I use npm instead of pnpm.

@waldi
Copy link

waldi commented Mar 8, 2024

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

@jercomio
Copy link

jercomio commented Mar 8, 2024

which pnpm

No, for me it's /usr/local/bin/pnpm

digitalsp added a commit to digitalsp/misskey-for-moge that referenced this issue Mar 9, 2024
….jsonでのpnpmのバージョンアップ

[参考Issue](pnpm/pnpm#6424)

まだテストしてない、マージしてコンフリクト解消しただけ
ericallam added a commit to triggerdotdev/trigger.dev that referenced this issue Mar 27, 2024
@stub4ever
Copy link

Don't forget to update the version in your package.json if it was set!

"packageManager": "pnpm@8.3.1"

This was the solutions for me updated the packagesManager into "pnpm@8.3.1"

@mxdlzg
Copy link

mxdlzg commented Apr 25, 2024

Still happen with pnpm 9.0.6 and node v20.11.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment