berry
berry copied to clipboard
[Bug?]: Yarn 4 resets "bin" field in package.json after install/link operations
Self-service
- [ ] I'd be willing to implement a fix
Describe the bug
When using Yarn 4.2.2, the "bin" field in the package.json file is being reset to "bin": "./dist/index.js" after running any Yarn command that includes install steps, such as yarn link, yarn, or yarn install. This behavior makes it impossible to customize the "bin" field for a Node CLI project.
To reproduce
- Create a new Node.js project.
- Add a "bin" field to the
package.jsonfile, specifying a custom script path:{ // ... "packageManager": "[email protected]", "bin": { "my-script": "./dist/index.js" }, // ... } - Run any of the following Yarn commands:
yarn linkyarnyarn install
- Observe that the "bin" field in the
package.jsonfile has been reset to"bin": "./dist/index.js".
Environment
System:
OS: macOS 14.5
CPU: (12) arm64 Apple M3 Pro
Binaries:
Node: 20.11.0 - /private/var/folders/8p/k84m_zzx6yz_s258bw82jt880000gr/T/xfs-4d591356/node
Yarn: 4.2.2 - /private/var/folders/8p/k84m_zzx6yz_s258bw82jt880000gr/T/xfs-4d591356/yarn
npm: 10.2.4 - ~/.nvm/versions/node/v20.11.0/bin/npm
bun: 1.1.8 - ~/.bun/bin/bun
Additional context
No response
Yarn reformats the package.json. If it did this change, it's that it wouldn't have had functional change (ie your package is called my-script, so "bin as a string" is implicitly mapped to the proper name).
Yarn reformats the package.json. If it did this change, it's that it wouldn't have had functional change (ie your package is called
my-script, so "bin as a string" is implicitly mapped to the proper name).
Thanks @arcanis. I mostly using npm previously. I am trying to figure it out how to ensure it work the same as npm way. If I do npm build and npm link I can simply test it in my local with npx my-script. Do you know how to do it in yarn, please?
I came here because I noticed the same behavior.
This is parts of my package.json file
{
"name": "setup-rwgc",
"version": "0.2.1",
"description": "Setup rwgc in a RedwoodJS project",
"repository": {
"type": "git",
"url": "https://github.com/Tobbe/setup-rwgc"
},
"main": "./dist/cli.js",
"bin": {
"setup-rwgc": "./dist/cli.js"
},
"scripts": {
So @arcanis, you're saying that because "name": "setup-rwgc" matches what I'm trying to map my bin to (setup-rwgc) that mapping is redundant and so yarn gets rid of it?
Ever since I noticed this I've just been manually reverting the change, because I didn't understand it. Thanks for explaining!
What do you think about logging a message explaining what's going on when yarn rewrites something like this?
Hi! 👋
It seems like this issue as been marked as probably resolved, or missing important information blocking its progression. As a result, it'll be closed in a few days unless a maintainer explicitly vouches for it.