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/npx crashes if stdout is Node's 'pipe' #2114
Comments
This works for me on Darwin and Linux, using npm 6.14.2, 6.14.8, 7.0.7, and v7.0.10, with node 14.2.0, 14.15.0, and 15.2.0.
When
I'm not sure why you'd be getting an empty error output though. Does it create a debug log file in |
Good testing @isaacs, however as mentioned in the original description this doesn’t repro on Node 14 or newer. I’ve not tested 13. It does happen under Node 12 - at least on my machine. And while I’d love to be running 14 and getting access to all the niceness it brings, several projects aren’t paying for that upgrade yet. As to your questions, again running under Ubuntu and Node 12 with NPM 7.
|
As an experiment I upgraded my node to 14: $ snap refresh --channel=14/stable node
node (14/stable) 14.14.0 from OpenJS Foundation (iojs✓) refreshed
$ node -v
v14.14.0
$ npm -v
7.0.7 And re-ran the test. So the following combination is failing the test command on my machine:
With the following log: |
More fun that might, or might not, help locate the origin of this issue: today I was trying to do some bash scripting around some npm commands and got a very similar interesting result: $ npm run build; echo $?
# <SNIP, runs fine>
0
$ npm run build 2> test; echo $?; cat test
243 There was no content in the The relevant line from This repros in both of the following configurations on Ubuntu 20.04.2 LTS, with node and npm installed via the official snap package:
Kinda looks like it really doesn't like being redirected away from a tty. |
@kc15155 I wasn't able to repro this on Node |
The point here isn't rimraf. I chose rimraf because it was simple and common. The point is that, under the conditions I specified, running npm or npx with the stderr routed to anything that's not a tty, like using it from node, things don't behave. |
This appears to have been fixed at least as of ~/D/n/s/fresh4 $ npx @gar/create-test > test; echo $status; cat test
0
Gar's test create script version 2.0.3 |
Current Behavior
Executing npm or npx commands from within a parent process that sets the child's stdout to "pipe" causes npm/npx to crash.
Expected Behavior
npm/npx to detect that this condition exists and proceed without issue.
Steps To Reproduce
Using Linux with Node 12 in a folder containing a valid package.json.
With rimraf already installed as a (optionally dev) dependency. I chose rimraf for this example as it is well-known and simple, but this reproduces with any command. I was originally having the problem with husky-run.
Execute the following:
or any of the following
results in
Workarounds
Environment
Under Alpine's Node 14 I was unable to reproduce, likely due to Node having changed behavior. These two configurations are what I have at hand. I did first detect the issue on my Ubuntu 20.04 with Node 12 and npm 6 setup before I upgraded npm to 7.
Notes
This fundamental problem is the source of several bug reports over the years in many repositories, so I have no doubt that an issue exists that already documents this bug - but I've been unable to find it.
The text was updated successfully, but these errors were encountered: