You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Corepack not adding packageManager field to package.json #560
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:
brew install node@20
brew link --overwrite node@20
corepack enable
corepack prepare pnpm@latest --activate
pnpm setup
mkdir test
cd test
pnpm init
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?
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.
Reacted by Ari Palo, gleb, Andrew, Rémi Chanaud and ensconced
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!
@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?
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.
Activity
aduh95 commentedon Sep 11, 2024
I suspect the
pnpmyou use is not provided by Corepack. What doescommand -v pnpmoutput on your machine?ProchaLu commentedon Sep 11, 2024
@aduh95 The output is
aduh95 commentedon Sep 11, 2024
Can you show the output of those commands if you set
DEBUG=corepackin your env?ProchaLu commentedon Sep 11, 2024
aduh95 commentedon Sep 11, 2024
Well it looks like you have a
packge.jsonin your $HOME, and I suppose that's where thepackageManagerfield is defined. Consider removing that file, it seems like a bad idea to have that.ProchaLu commentedon Sep 11, 2024
@aduh95 Thx! Removing the $HOME
package.jsonsolved the issue!ProchaLu commentedon Sep 11, 2024
@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?arcanis commentedon Sep 11, 2024
No, since in a workspace setup the
package.jsonthat defines the package manager is located at the top of the project tree.aduh95 commentedon Sep 11, 2024
In the case of a monorepo, you wouldn't want to define a
packageManagerper package, but rather at the project root.bojidar-bg commentedon Oct 20, 2025
Just ran into this myself with a
package.jsonin$HOME; would have appreciated if corepack didn't cross git repository boundaries when looking for the rootpackage.json.