npm / npm/cli

[BUG] Different behavior for npm pkg for root package and workspaces

Open
#5,481 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug cmd:pkg config:display Priority 2
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

I have a project with packages defined as workspaces

If i run the following command in the root folder - it works as expected

/gitlab-ci-cli (main) $ npm pkg get name
"gitlaber"

if i run same command for workspace - it always responds with json:

gitpod /workspace/gitlab-ci-cli/packages/commands (main) $ npm pkg get name
{
  "@gitlaber/commands": "@gitlaber/commands"
}

Using --json=false doesn't help. So it looks like somewhere --json is used internally

Expected Behavior

This command should work identically for all packages respecting --json parameter

Steps To Reproduce
  1. Init project
  2. Add workspace project
  3. run npm pkg get name in the root folder
  4. run npm pkg get name in the workspace folder

Output format is different

Environment
  • npm: 8.19.1
  • Node.js: 16.17.0

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 two npm pkg get name commands in a project with a root package and workspace, including --json=false, using the reported npm and Node.js versions if available. Compare the root and workspace output paths; done means both packages respect the requested JSON format consistently.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.