npm / npm/cli

[BUG] `npm explain` on repo with large # of packages fails with `invalid string length`

Open
#6,361 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Priority 2 Release 9.x
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

Is there an existing issue for this?
  • I have searched the existing issues
This issue exists in the latest npm version
  • I am using the latest npm
Current Behavior

In a monorepo with a large number of packages in an npm workspace, the npm explain command fails to return.

Expected Behavior

A more useful error should be returned, or the output format of npm explain should be amended to make the output smaller and more useful.

For the other corepack package managers:

  • yarn why returns a compact output and succeeds
  • pnpm why crashes with heap out of memory errors
Steps To Reproduce
  1. In my reproduction repository: https://github.com/forivall/npm-explain-invalid-string-length-repro
  2. Run npm explain yargs or npm explain yargs --json
  3. See the error npm ERR! Invalid string length
    • or, with --json, we see
       npm ERR! Invalid string length
       {
         "error": {
           "code": null,
           "summary": "Invalid string length",
           "detail": ""
         }
       }
      
Environment
  • npm: 8.19.4
  • Node.js: v16.17.0
  • OS Name: macOS 13.3.1
  • System Model Name: Macbook Pro
  • npm config:
; "user" config from /Users/emily.klassen/.npmrc

//registry.npmjs.org/:_authToken = (protected)
email = "forivall@gmail.com"
init-author-name = "emily"
legacy-peer-deps = true

; node bin location = /Users/emily.klassen/.nvm/versions/node/v16.17.0/bin/node
; node version = v16.17.0
; npm local prefix = /Users/emily.klassen/code/public/npm-explain-invalid-string-length-repro
; npm version = 8.19.4
; cwd = /Users/emily.klassen/code/public/npm-explain-invalid-string-length-repro
; HOME = /Users/emily.klassen
; Run `npm config ls -l` to show all defaults.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the failure in the linked npm-explain-invalid-string-length-repro repository with npm explain yargs and npm explain yargs --json. Trace the npm explain CLI path involved in producing the oversized output. Done means the command no longer fails with Invalid string length and returns either a useful error or smaller, more useful output.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.