berry
berry copied to clipboard
[Bug]: Calling `yarn rebuild` in postinstall calls it infinitely recursively
Self-service
- [X] I'd be willing to implement a fix
Describe the bug
When calling yarn rebuild in a postinstall script, the rebuild command will call the postinstall script after being finished (or before? doesn't matter), which will call rebuild again and do so indefinitely.
This behavior doesn't happen on NPM which I presume does not run postinstall after npm rebuild, but apparently Yarn does. Since Yarn doesn't provide a way to disable scripts for rebuild, I can't do something like "postinstall": "yarn rebuild --ignore-scripts sharp", and disabling it globally via .yarnrc.yml would also ruin the purpose.
I know that the doc recommends not to use postinstall, but since I'm running my project in a Docker container (Linux + MUSL) with a node_modules created with Yarn in local (on Darwin), I have to use this script to rebuild sharp for the linuxmusl platform (alongside the darwin platform it was originally built with) so that it can run in the container. (Related to #3853)
The reason I made this postinstall script is that using supportedArchitectures also doesn't work for sharp (which uses .node bindings in itself), but does for esbuild (which uses a separate dependency for each platform). This could make another issue maybe?
To reproduce
This can be reproduced by running yarn with the following package.json:
{
"name": "test",
"scripts": {
"postinstall": "yarn rebuild sharp"
},
"dependencies": {
"sharp": "^0.31.0"
},
"packageManager": "[email protected]"
}
Environment
System:
OS: macOS 12.4
CPU: (16) x64 AMD Ryzen 7 3800X 8-Core Processor
Binaries:
Node: 18.8.0 - /private/var/folders/4_/k05ccxxd13j3n60930rkvz880000gn/T/xfs-c714cf0d/node
Yarn: 3.2.3 - /private/var/folders/4_/k05ccxxd13j3n60930rkvz880000gn/T/xfs-c714cf0d/yarn
npm: 8.18.0 - ~/.nix-profile/bin/npm
Additional context
It's my first time using the new Yarn version, I migrated to use the supportedArchitectures feature for the Docker platform compatibility issue I had with esbuild and sharp as described earlier, but sadly it didn't fix it for sharp without the postinstall script, which itself only works using npm and not yarn. Since it works running npm in the postinstall script and still using yarn, this isn't a major issue, but still is a bug I felt had to be reported.
Instead of adding yarn rebuild to postinstall you can call yarn rebuild directly which also performs an install.
I know, but then this won't be automatic and I'll have to change the install process of this project (which I'm definitely not alone on), which I do not have to do if I use npm rebuild :/
Hi! 👋
This issue looks stale, and doesn't feature the reproducible label - which implies that you didn't provide a working reproduction using Sherlock. As a result, it'll be closed in a few days unless a maintainer explicitly vouches for it or you edit your first post to include a formal reproduction (you can use the playground for that).
Note that we require Sherlock reproductions for long-lived issues (rather than standalone git repositories or similar) because we're a small team. Sherlock gives us the ability to check which bugs are still affecting the master branch at any given point, and decreases the amount of code we need to run on our own machines (thus leading to faster bug resolutions). It helps us help you! 😃
If you absolutely cannot reproduce a bug on Sherlock (for example because it's a Windows-only issue), a maintainer will have to manually add the upholded label. Thanks for helping us triaging our repository! 🌟