DEV Community

Cover image for Fixing `ERR_INVALID_THIS` on Vercel by Switching from pnpm to Bun
阿豪
阿豪

Posted on

Fixing `ERR_INVALID_THIS` on Vercel by Switching from pnpm to Bun

When deploying on Vercel with Node.js 20+, I ran into a frustrating error during pnpm install:


(ERR_INVALID_THIS). Will retry in 10 seconds. 2 retries left.
Enter fullscreen mode Exit fullscreen mode

No matter what I tried, I couldn’t get rid of it. The only workaround was to fall back to Node.js 18, but Vercel is deprecating Node 18 support soon.

After exhausting all the solutions I could find, I decided to try switching to Bun.

Running:

bun install
Enter fullscreen mode Exit fullscreen mode

worked perfectly — no more errors! 🎉

Thanks to Bun, my builds are running smoothly again. It truly saved the day. 🙌

Top comments (2)

Collapse
 
harjjotsinghh profile image
Harjot Singh

deploy stack matters less than what gets built on top. moonshift writes auth/billing/deploy as defaults, ships your code to YOUR github + vercel for $3 flat per run. first run free, no card. moonshift.io

Collapse
 
harjjotsinghh profile image
Harjot Singh

Nice catch. ERR_INVALID_THIS on Vercel with Node 20+ is one of those errors where the message tells you nothing and the real fix is "change your package manager." Root cause is usually a fetch/undici version mismatch between what the package manager resolves and what the runtime expects, and swapping pnpm for Bun sidesteps it by changing resolution entirely. Worth flagging for anyone reading: it can also bite via a stale lockfile pinning an old undici, so a clean reinstall sometimes fixes it without switching tools. Build/runtime-target mismatches like this are exactly the class of thing that silently breaks a deploy, which is why I have Moonshift pin and verify the toolchain as part of shipping instead of discovering it in prod. Did Bun also cut your cold build times, or just kill the error?