Skip to content

[BUG] npm version fails when using --include-workspace-root with no root package.json name #5580

@msrose

Description

@msrose

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

Running npm version <inc> --include-workspace-root --workspaces throws npm ERR! Cannot read properties of undefined (reading '0') if the workspace root doesn't have a name field in its package.json.

Expected Behavior

The version command should not throw an error if the workspace root doesn't have a name field.

Steps To Reproduce

package.json:

{
  "workspaces": [
    "packages/*"
  ],
  "version": "1.3.0"
}

packages/one/package.json:

{
  "name": "one",
  "version": "1.3.0"
}

Running npm version minor --include-workspace-root --workspaces gives the following error:

undefined
v1.4.0
one
v1.4.0
npm ERR! Cannot read properties of undefined (reading '0')

Upon adding a name field to the workspace root, the command succeeds:

package.json:

{
  "name": "root",
  "workspaces": [
    "packages/*"
  ],
  "version": "1.4.0"
}

npm version minor --include-workspace-root --workspaces:

root
v1.5.0
one
v1.5.0

Environment

  • npm: 8.19.2
  • Node.js: v16.17.0
  • OS Name: macOS Monterey 12.5.1
  • System Model Name: Macbook Pro
  • npm config:
; node bin location = /Users/msrose/.nvm/versions/node/v16.17.0/bin/node
; node version = v16.17.0
; npm local prefix = /Users/msrose/test-stuff/test-npm-bug
; npm version = 8.19.2
; cwd = /Users/msrose/test-stuff/test-npm-bug
; HOME = /Users/msrose

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingNeeds Triageneeds review for next stepsRelease 8.xwork is associated with a specific npm 8 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions