Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I fix Error: spawn UNKNOWN with node.js v7.8.0 on windows 10?

I'm getting an error on windows 10 when I try to run spawn

  var spawn = require('child_process').spawn;
  var child = spawn(path.join(__dirname, '../bin/run.js'), {}, {env: env});
  child.stdout.pipe(process.stdout);
  child.stderr.pipe(process.stderr);

Here is the error message. I couldn't find much about resolving this issue.

[14:58:15] Error: spawn UNKNOWN

I installed node with nvs which appears to be working fine for everything else.

So I figured out its the run.js which is a node script with a shebang, but that doesn't work on windows.

I tried changing it to spawn('node run.js') but now I get NOENT.

like image 974
chovy Avatar asked Apr 14 '17 22:04

chovy


People also ask

How do you spawn in node JS?

The spawn function launches a command in a new process and we can use it to pass that command any arguments. For example, here's code to spawn a new process that will execute the pwd command. const { spawn } = require('child_process'); const child = spawn('pwd');

What is node spawn?

spawn() : The spawn function launches a command in a new process and you can use it to pass that command any arguments. It's the most generic spawning function and all other functions are built over it [docs]. child_process. execFile() : The execFile function is similar to child_process.


1 Answers

I had to pass an array of args to node. On windows shebang lines don't work so the command I'm executing is actually node and the path to the run.js is an argument.

spawn('node', ['run.js']) works.

like image 167
chovy Avatar answered Oct 11 '22 14:10

chovy