pnpm: [Regression]:  ERROR  Invalid string length (RangeError: Invalid string length)

Last pnpm version that worked

8.7.0

pnpm version

These don’t work: 8.7.4 and 8.7.5

Code to reproduce the issue

I don’t have any specific or special code to reproduce it. It happens on any standard repo. It appears to be endemic to workspace-based repos…I think

To test it --> Use this

You can test this out on the following boilerplate (it happens here, at least on my machine):

https://github.com/antfu/vitesse

  • Just add a pnpm-workspace.yaml
  • move everything into into packages/<something>
  • try to run an installation

Expected behavior

Installation works without errors…we’re just installing a set of packages, and it’s not even a huge set of packages.

Actual behavior

Attempting to install the packages in my workspace, using pnpm 8.7.4

❯ npx pnpm@latest i
Need to install the following packages:
  pnpm@8.7.4
Ok to proceed? (y) Y
Scope: all 4 workspace projects
 ERROR  Invalid string length

RangeError: Invalid string length
    at JSON.stringify (<anonymous>)
    at calcDepState (/Users/x3r0/.npm/_npx/de6729f694090229/node_modules/pnpm/dist/pnpm.cjs:122538:29)
    at /Users/x3r0/.npm/_npx/de6729f694090229/node_modules/pnpm/dist/pnpm.cjs:124082:69

Check current version of (working) pnpm

❯ pnpm --version
8.7.0

Run current working version of pnpm@8.7.0

❯ pnpm i
Scope: all 4 workspace projects
../../amplify/backend/function/arangoTest/node_modules/.pnpm/esbuild@0.19.2/node_modules/esbuild: Running postinstall script, done in 137ms
node_modules/.pnpm/simple-git-hooks@2.9.0/node_modules/simple-git-hooks: Running postinstall script, done in 93ms
node_modules/.pnpm/esbuild@0.18.20/node_modules/esbuild: Running postinstall script, done in 133ms
node_modules/.pnpm/cypress@13.1.0/node_modules/cypress: Running postinstall script, done in 307ms
node_modules/.pnpm/sharp@0.32.5/node_modules/sharp: Running install script, done in 1.1s
node_modules/.pnpm/vue-demi@0.14.6_vue@3.3.4/node_modules/vue-demi: Running postinstall script, done in 67ms
node_modules/.pnpm/json-editor-vue@0.10.15_vanilla-jsoneditor@0.17.10_vue@3.3.4/node_modules/json-editor-vue: Running preinstall script, done in 34ms
node_modules/.pnpm/json-editor-vue@0.10.15_vanilla-jsoneditor@0.17.10_vue@3.3.4/node_modules/json-editor-vue: Running postinstall script, done in 33ms
. postinstall$ npx simple-git-hooks
│ [INFO] Successfully set the pre-commit with command: npx lint-staged
│ [INFO] Successfully set all git hooks
└─ Done in 476ms
Done in 6.2s

Additional information

A regression? Okay…but of what?

I looked for any related issues, and found the following: https://github.com/pnpm/pnpm/issues/4949

The behavior I’m observing appears to be consistent with what’s in this bug report, therefore I assume that this is a regression.

Node.js version

18.16.1

Operating System

macOS

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 20 (7 by maintainers)

Commits related to this issue

Most upvoted comments

We should fix it for sure but I can’t reproduce the issue.

This is probably the same issue as this one: https://github.com/pnpm/pnpm/issues/5056

Looks like using an object hash instead of JSON.stringify could be the solution but I wasn’t able to break JSON.stringify yet to verify the fix.

As a temporary fix, I think you can just disable side effects cache by setting side-effects-cache to false.