Skip to content

Corepack not adding packageManager field to package.json  #560

Closed

Description

@ProchaLu

When using Homebrew to install Node.js, enabling Corepack, and then using Corepack to manage pnpm, Corepack does not add a packageManager field to my package.json. This field should be automatically added, but it is missing, requiring me to add it manually.

Setting the COREPACK_ENABLE_AUTO_PIN=1 in zshrc does not resolve the issue. Even after reinstalling Corepack and Node.js, the problem still exists.

Steps to Reproduce:

  1. brew install node@20
  2. brew link --overwrite node@20
  3. corepack enable
  4. corepack prepare pnpm@latest --activate
  5. pnpm setup
  6. mkdir test
  7. cd test
  8. pnpm init
  9. corepack use pnpm@latest or pnpm install

Expected Behavior

Corepack should automatically add the packageManager field to package.json when using pnpm.

Actual Behavior

The packageManager field is not added, and setting COREPACK_ENABLE_AUTO_PIN=1 in ~/.zshrc does not fix the issue. Reinstalling Corepack and Node.js does not resolve the problem either.

Additional Information

Node.js v20.17.0
Corepack 0.29.3
pnpm 9.10.0

How can I set the environment variable to enable this functionality, and are there any other steps to resolve this issue?

Activity

  1. aduh95 commented on Sep 11, 2024

    @aduh95
    Contributor

    I suspect the pnpm you use is not provided by Corepack. What does command -v pnpm output on your machine?

  2. ProchaLu commented on Sep 11, 2024

    @ProchaLu
    Author

    I suspect the pnpm you use is not provided by Corepack. What does command -v pnpm output on your machine?

    @aduh95 The output is

    command -v pnpm
    /opt/homebrew/opt/node@20/bin/pnpm
    
  3. aduh95 commented on Sep 11, 2024

    @aduh95
    Contributor

    Can you show the output of those commands if you set DEBUG=corepack in your env?

  4. ProchaLu commented on Sep 11, 2024

    @ProchaLu
    Author
    ➜  echo 'export DEBUG=corepack' >> ~/.zshrc
    ➜  source ~/.zshrc
    ➜  command -v pnpm
    /opt/homebrew/opt/node@20/bin/pnpm
    ➜  node -v
    v20.17.0
    ➜  corepack -v
    0.29.3
    ➜  pnpm -v
      corepack LastKnownGood file would be located at /Users/lukas/.cache/node/corepack/lastKnownGood.json +0ms
      corepack Search for default version: Found pnpm@9.10.0 in LastKnownGood file +2ms
      corepack Checking /Users/lukas/Documents/projects/test/package.json +0ms
      corepack Checking /Users/lukas/Documents/projects/package.json +0ms
      corepack Checking /Users/lukas/Documents/package.json +0ms
      corepack Checking /Users/lukas/package.json +1ms
      corepack Using pnpm@9.10.0+sha512.73a29afa36a0d092ece5271de5177ecbf8318d454ecd701343131b8ebc0c1a91c487da46ab77c8e596d6acf1461e3594ced4becedf8921b074fbd8653ed7051c as defined in project manifest /Users/lukas/package.json +0ms
      corepack Reusing pnpm@9.10.0 found in /Users/lukas/.cache/node/corepack/v1/pnpm/9.10.0 +3ms
    9.10.0
    
  5. aduh95 commented on Sep 11, 2024

    @aduh95
    Contributor

    Well it looks like you have a packge.json in your $HOME, and I suppose that's where the packageManager field is defined. Consider removing that file, it seems like a bad idea to have that.

  6. ProchaLu commented on Sep 11, 2024

    @ProchaLu
    Author

    Well it looks like you have a packge.json in your $HOME, and I suppose that's where the packageManager field is defined. Consider removing that file, it seems like a bad idea to have that.

    @aduh95 Thx! Removing the $HOME package.json solved the issue!

  7. ProchaLu commented on Sep 11, 2024

    @ProchaLu
    Author

    @aduh95, thx for your time, but there is a question if the current directory has a package.json, wouldn't a user expect that Corepack would change that one, and not one way further up in the tree?

  8. arcanis commented on Sep 11, 2024

    @arcanis
    Contributor

    wouldn't a user expect that Corepack would change that one, and not one way further up in the tree?

    No, since in a workspace setup the package.json that defines the package manager is located at the top of the project tree.

  9. aduh95 commented on Sep 11, 2024

    @aduh95
    Contributor

    In the case of a monorepo, you wouldn't want to define a packageManager per package, but rather at the project root.

  10. bojidar-bg commented on Oct 20, 2025

    @bojidar-bg

    Just ran into this myself with a package.json in $HOME; would have appreciated if corepack didn't cross git repository boundaries when looking for the root package.json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions