Skip to content

[Bug]: Calling yarn rebuild in postinstall calls it infinitely recursively #4876

@Litarvan

Description

@Litarvan

Self-service

  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingupholdedReal issues without formal reproduction

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions