-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] "npm rebuild" with v7 runs the postinstall script, whereas it did not run the postinstall script with npm v6 (can cause unexpected endless loop) #2670
Comments
Technically, this package.json is the minimal reproducer: {
"scripts": {
"postinstall": "npm rebuild"
}
} (And then run But you could have a more complex postinstall script that does something useful and then runs Real world example: The package manager for the Atom text editor does this and is infinitely looping with npm 7: (It bundles a specific copy of Node to run itself with, and so during postinstall it needs its own native dependencies to be rebuilt with its bundled Node, as opposed to built against whatever different version of Node the user might have on their PATH.) |
I can reproduce this issue. Seems like a regression in npm 7, which results in infinite loops when you use |
This bug doesn't happen with npm <= v7.1.0, but it does happen with v7.1.1 and higher. 7.1.1+ are affected. |
@DeeDeeG as a quick question, wondering why you need to be running |
Hi @darcyclarke. I considered writing out the use case in detail above but didn't want to be too verbose. Here's the details:
We ( Potential workaround for apm (click to expand):
More context and my thoughts: Workarounds for I think there are many situations where you'd just want to rebuild native code, rather than "rebuild native code and also run your postinstall scripts". And I can't foresee as many situations where "rebuild and run postinstall scripts" is more desirable. Having it just rebuild is much more composable for scripting. Having it do both means some rather involved or awkward workarounds might be required, as in
👍 Whatever the outcome that gets decided, more documentation would be great! P.S. for the record I'm not an official member of the Atom team. I'm a regular contributor from the comunity. And a lot of the core work of that text editor is actually being done by community members now that the main team is pretty lean on personnel and work hours devoted to Atom. |
The short version is:
Oh, and the main Atom repo treats |
|
I have a bad habit of saying things with way too long posts. We find it extremely useful to make sure "the version of Node running Edit to add: (And we really want to make sure this is handled by If there are more specific follow-up questions about this use-case, I'd be glad to answer. (And I'll try to keep the answers concise and to the point.) Thanks for your time. |
Right, i totally get that - but npm rebuild inside a postinstall script is going to be for the same version of node that did the install, no? Running npm rebuild on its own, from another node version, seems like it would achieve what you want. |
We have a project-local shim for
That's what we're doing and where we're seeing the endless loops. The top post of this issue has a farcical but minimal reproducer. It is what our real use case boils down to, in some sense. (Minus the real-world useful stuff that we do.) This used to make sense to do in a postinstall script. But now it loops. (If we manually "ran npm on its own with another node version", given this bug (IMO it's a bug), rebuilding would hit the |
I acknowledge that our use-case us unusual, but I personally maintain that This is less about whether running A lot of What is the use-case for |
You can't assume that people don't do that. Automatically, running If this is the desired behavior you should bump the Please open the issue. The severity of this bug is more than the documentation. |
In my opinion Times when I'm rebuilding the native C++ code are rarely (pretty much never) times when the project is in a state ready for |
@DeeDeeG / @aminya appreciate the extra context, again we've got another issue/spike in the works that should further lement lifecycle scripts; I believe there's been some confusion & 100% a lack of concrete documentation in this space which isn't good. We can circle back on this early next week but I should note that we will probably further document/outline how |
@darcyclarke @ljharb thanks for continuing to engage here. I hope it's not too redundant to this issue, but I posted this as a "feature sugestion" over here: npm/feedback#218. I want to be able to voice an opinion about what the intended behavior should be in npm 7, and potentially let there be a space for community discussion and comments, and it's seems like perhaps that's the right way to do that rather than a bug report. Best regards. |
The problem is wider than I initially realized: |
Okay. I've fully made the case as well as I can make it, above. I would like to suggest a couple of things, assuming the current
|
Current Behavior:
Putting
npm rebuild
in a postinstall script can cause an infinite loop with npm v7.Expected Behavior:
npm rebuild
used to not trigger the postinstall script (so, no infinite loop) with npm v6.Steps To Reproduce:
mkdir x && cd x && npm init -y
package.json
:"postinstall": "npm rebuild"
npm install
ornpm rebuild
i.
npm install --verbose
shows what's going on clearer.npm install
runspostinstall
which runsrebuild
which triggerspostinstall
which runsrebuild
... ♾️Environment:
The text was updated successfully, but these errors were encountered: