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

TypeError: Cannot read property 'on' of null #35473

Closed
BumpyBill opened this issue Oct 2, 2020 · 3 comments
Closed

TypeError: Cannot read property 'on' of null #35473

BumpyBill opened this issue Oct 2, 2020 · 3 comments
Labels
child_process Issues and PRs related to the child_process subsystem. wsl Issues and PRs related to the Windows Subsystem for Linux.

Comments

@BumpyBill
Copy link

What steps will reproduce the bug?

const { spawn } = require("child_process");

const deploy = spawn("sh", ["-c", `node server && ls`], {
  stdio: ["inherit", "inherit", "inherit"],
});

console.log(deploy.pid); // I use this to get the PID so i can use the kill command

deploy.stdout.on("data", (data) => {
  console.log(data.toString());
});

deploy.stderr.on("data", (data) => {
  console.log(data.toString());
});

deploy.on("exit", (code) => {
  console.log("exit");
});

How often does it reproduce? Is there a required condition?

From what I can tell, it seems to happen every time

What is the expected behavior?

To run the code as it would

What do you see instead?

deploy.stdout.on("data", (data) => {
             ^

TypeError: Cannot read property 'on' of null
    at Object.<anonymous> (/mnt/c/Users/624234/Desktop/Testing/aaaa/index.js:9:14)
    at Module._compile (module.js:577:32)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Module.runMain (module.js:611:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:160:9)
    at bootstrap_node.js:507:3
@BumpyBill
Copy link
Author

BumpyBill commented Oct 3, 2020

After doing a bit of debugging, thedeploy variable is equal to:

ChildProcess {
  domain: null,
  _events: {},
  _eventsCount: 0,
  _maxListeners: undefined,
  _closesNeeded: 1,
  _closesGot: 0,
  connected: false,
  signalCode: null,
  exitCode: null,
  killed: false,
  spawnfile: 'sh',
  _handle: Process { owner: [Circular], onexit: [Function], pid: 3439 },
  spawnargs: [ 'sh', '-c', 'node server && ls' ],
  pid: 3439,
  stdin: null,
  stdout: null,
  stderr: null,
  stdio: [ null, null, null ]
}

@JamesGaier
Copy link

I was reading the documentation on child processes and I noticed that if you pass anything other than 'pipe' to stdio[1], stdout is set to null.

@watilde watilde added child_process Issues and PRs related to the child_process subsystem. wsl Issues and PRs related to the Windows Subsystem for Linux. labels Oct 16, 2020
@targos
Copy link
Member

targos commented Dec 28, 2020

This is not a bug and documented, so I'll close the issue.

@targos targos closed this as completed Dec 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
child_process Issues and PRs related to the child_process subsystem. wsl Issues and PRs related to the Windows Subsystem for Linux.
Projects
None yet
Development

No branches or pull requests

4 participants