Skip to content
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

Specify stdio option when invoking package manager #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dave-irvine
Copy link

@dave-irvine dave-irvine commented Jan 28, 2022

When this option isn't specified, yarn errors out (npm does not do this). This error only seems to occur for some people and not all. I haven't been able to narrow down the conditions that induce the error, it suddenly started happening to me today.

Sample script:

const exec = require('child_process').execSync;

exec('yarn run postinstall', {});

Output:

node test.js || echo "Exit code: $?"
child_process.js:866
    throw err;
    ^

Error: Command failed: yarn run postinstall
    at checkExecSyncError (child_process.js:790:11)
    at execSync (child_process.js:863:15)
    at Object.<anonymous> (/tmp/test/test.js:3:1)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47 {
  status: 1,
  signal: null,
  output: [ null, Buffer(0) [Uint8Array] [], Buffer(0) [Uint8Array] [] ],
  pid: 12204,
  stdout: Buffer(0) [Uint8Array] [],
  stderr: Buffer(0) [Uint8Array] []
}
Exit code: 1

Fixed script:

const exec = require('child_process').execSync;

exec('yarn run postinstall', { stdio: 'ignore' });

Output:

node test.js && echo "Exit code: $?"
Exit code: 0

Node version

$ node -v
v14.18.3

Yarn version

$ yarn -v
1.22.17

Fixes #7

When this option isn't specified, `yarn` errors out (`npm` does not do this).

```js
const exec = require('child_process').execSync;

exec('yarn run postinstall', {});
```

```
node test.js || echo "Exit code: $?"
child_process.js:866
    throw err;
    ^

Error: Command failed: yarn run postinstall
    at checkExecSyncError (child_process.js:790:11)
    at execSync (child_process.js:863:15)
    at Object.<anonymous> (/tmp/test/test.js:3:1)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47 {
  status: 1,
  signal: null,
  output: [ null, Buffer(0) [Uint8Array] [], Buffer(0) [Uint8Array] [] ],
  pid: 12204,
  stdout: Buffer(0) [Uint8Array] [],
  stderr: Buffer(0) [Uint8Array] []
}
Exit code: 1
```

```js
const exec = require('child_process').execSync;

exec('yarn run postinstall', { stdio: 'ignore' });
```

```
node test.js && echo "Exit code: $?"
Exit code: 0
```
Copy link

@danofsteele danofsteele left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, haven't had my coffee yet this morning!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Command failed with exit code 1. (checkExecSyncError)
2 participants