child_process in Node js Google App Engine - node.js

I have a Node Express server that works on localhost. It uses child_process to run a C++ standalone executable.
The code that uses child_process is the following (the application creates output.txt):
app.post('/generate', async function(req, res)
{
var input1 = req.body.input1;
var input2 = req.body.input2;
var execFile = require('child_process').execFile;
var program = "path/to/executable";
var args = [input1, input2];
var child = execFile(program, args,
function (error, stdout, stderr){
console.log(error);
console.log(stdout);
console.log(stderr);
const file = __dirname + "/output.txt"
app.get('/output.txt', function (req, res) {
res.sendFile(path.join(__dirname + '/output.txt'));
});
res.send("/output.txt");
})
})
This works locally.
I'm now trying to deploy it on Google Cloud Platform with App Engine.
However, when I go the website that I host, and launch this POST /generate request, I don't get the expected output. In the Google Cloud Platform logs of my project I can see the following error:
textPayload: "{ Error: spawn cpp/web_cpp_app/x64/Debug/web_cpp_app ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
at onErrorNT (internal/child_process.js:415:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
"
At first I didn't understand the error, but now I can see that if I locally run the same project, but set the path of the standalone executable to an invalid path, I get the same error. I'm guessing that when I deploy, my executable is somehow not included?
Is there something specific I need to add in package.json or app.yaml files, to include the executable?
EDIT:
Could it be that the app engine runs on Linux, and my executable is for Windows?

ENOENT means "no such file or directory", so your path could be wrong, or the container doesn't recognize the program as executable.
But either way, you will need to build and include a linux-compatible binary of your child_process program in your project directory when you deploy. You could build this manually, or use something like Cloud Build to compile it in a container that's identical to that of App Engine.

You are right about the OS, per this Doc Appengine standard for NodeJS uses Ubuntu OS, and flexible uses Debian
About the executable compatibility I found this post

Related

Error when executing npm command in firebase cloud functions

I've a project with the following folder structure:
enter image description here
It has a firebase cloud functions folder as well as a react app.
Here's the code for the index.js file in the functions folder:
const functions = require("firebase-functions");
const { exec } = require("child_process");
const util = require("util");
const execPromise = util.promisify(exec);
exports.installModules = functions.https.onCall((data, context) => {
return new Promise((resolve, reject) => {
console.log("Starting install modules process");
exec(
"npm i",
{
cwd: "../react-app",
},
(err, stdout, stderr) => {
if (err) {
console.error("Error running build command:", err);
reject(err);
}
console.log("Modules installed successfully with output:", stdout);
resolve("Modules installed successfully");
}
);
});
});
exports.build = functions.https.onCall((data, context) => {
return new Promise((resolve, reject) => {
console.log("Starting build process...");
exec(
"npm run build",
{
cwd: "../react-app",
},
(err, stdout, stderr) => {
if (err) {
console.error("Error running build command:", err);
reject(err);
}
console.log("Build completed successfully with output:", stdout);
resolve("Build completed successfully");
}
);
});
});
The first function (installModules) installs modules inside the react app. The second function (build) makes a build folder for the react app. Both of these functions work fine when testing them with the firebase functions shell (with the command firebase functions:shell, and then nameOfFunction({}).
However, when running deploying these to the cloud I get the following error when calling them from a frontend.
**severity: "ERROR"
textPayload: "Unhandled error Error: spawn /bin/bash ENOENT
at Process.ChildProcess._handle.onexit (node:internal/child_process:285:19)
at onErrorNT (node:internal/child_process:485:16)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn /bin/bash',
path: '/bin/bash',
spawnargs: [ '-c', 'npm i' ],
cmd: 'npm i'
}**
I've tried running these in an express server deployed to both Google Cloud and Heroku but was running into too many issues which is why I decided to give firebase cloud functions a try. According to this post it is possible to run npm commands inside of a google function.
Thanks, any help is appreciated!
What you're trying to do isn't possible. You can't dynamically install modules or do anything at all to modify the filesystem that was created for your function (it is a read-only docker image). From the documentation:
The function execution environment includes an in-memory file system that contains the source files and directories deployed with your function (see Structuring source code). The directory containing your source files is read-only, but the rest of the file system is writeable (except for files used by the operating system). Use of the file system counts towards a function's memory usage.
The question you linked does not actually say that it's possible to run npm commands in Cloud Functions. It just says that it's possible to spawn commands (typically that you provide in your own deployment).
If you want to run arbitrary commands to build a filesystem that you can use to execute more programs, Cloud Functions is not the right product for your use case. If you are just trying to build some software and deploy it somewhere, maybe Cloud Build is what you need as part of your deployment pipeline.
The issue I see is you are trying to execute /bin/bash shell scripting through exec within a Firebase function. Although it may be possible, I think you've outgrown Firebase in this regard and may want to look into using Cloud Run which has full access to shell without restriction and can still communicate with your GCFs (Firebase functions).
Creating a Cloud Run service is really easy with the pre-made container images you can use in the Google Cloud Console GUI so you can be up and running quickly.

How to find an .exe file path using node js

I'm running electron and nodejs on Windows 10
How can I find a path to an executable?
one way would be to run a cli command that will use something like
where myfile.exe
is there a node-ish way?
Use which module:
var which = require('which')
// async usage
which('node', function (er, resolvedPath) {
// er is returned if no "node" is found on the PATH
// if it is found, then the absolute path to the exec is returned
}).

NativeScript: require('child_process') gives an error when running "tns run ios --emulator"

I have a experiment code like this just to test calling a child process from NativeScript app (myapp/app/views/login/login.js):
var exec = require('child_process').exec;
exec('ls', function (error, stdout, stderr) {
if(stdout){
console.log('stdout: ' + stdout);
}
if(stderr){
console.log('stderr: ' + stderr);
}
if (error !== null) {
console.log('Exec error: ' + error);
}
});
when I test this app with "tns run ios --emulator", it gives an error like this:
file:///app/views/login/login.js:1:89: JS ERROR Error: Could not find module 'child_process'. Computed path '/Volumes/xxxx/Users/xxxx/Library/Developer/CoreSimulator/Devices/392A8058-694B-4A5D-B194-DF935815ED21/data/Containers/Bundle/Application/2822CD65-4E4D-443C-8272-135DB09353FC/sampleGroceries.app/app/tns_modules/child_process'.
My question is: how can I resolve this? Should I do "npm install child_process" on the app's directory? But while I was searching for solutions on Google, I read that it should be naturally included from node_modules...
I find a child_process module in:
/usr/local/lib/node_modules/nativescript/lib/common
but as the error message says, it isn't included when I execute the app with tns command. Could someone tell me what I'm missing?
version info:
npm: 3.10.10
node: 7.2.1
tns: 2.4.2
The child_process that you are seeing is a wrapper in the NativeScript CLI for Node's child_process.
There is no child_process in NativeScript as the concept is not relevant in mobile environments (Android/iOS).
The reason Node JS works cross-platform for example, is because its engine has analogous feature implementation (file-system, http, child process) for each of the supported platforms.
Using node's child_process (installing it explicitly and requiring it) will likely not work, as there is no in-house implementation for mobile devices.
If you would like to perform something in the background, consider using NativeScript's Workers.
http://docs.nativescript.org/angular/core-concepts/multithreading-model.html
Edit:
If there isn't a plugin already that is readily available, you could use the underlying native API to call to the device's shell.
Android: execute shell command from android
iOS (Objective C): Cocoa Objective-C shell script from application?
Docs on the nativescript site are available that should help you in 'translating' objC/Java code to JavaScript, though it is pretty straightforward.
http://docs.nativescript.org/runtimes/android/marshalling/java-to-js
http://docs.nativescript.org/runtimes/ios/marshalling/Marshalling-Overview

Assistance with Node.js functions integration in Apache Linux

Here is a short overview to help you experts understand the situation I am in - sorry that its too verbose, but it might help resolving this issue:
So I have a Linux machine, and it runs Apache properly.
Under '/var/www/html', I put my project files which are HTML (index.html) , and a javaScript file with utility functions.
httpd runs and everyone can view the content when 'http:///index.html' from their PC's.
I want to run a bash script from my Linux machine by letting the users provide the parameters from the front end user interface.
Reading how to do that, I saw tons of examples of how node.js can do that, so I downloaded Node.JS to my Linux machine, and it can be run from:
"
~/Desktop/node-v4.2.1-linux-x64/bin/node --version
v4.2.1
~/Desktop/node-v4.2.1-linux-x64/bin/npm --version
2.14.7
"
So it seems like its properly installed...
Note: I did not put anything in my Linux path after extracting the node.js tar.gz file.
Now, from my Linux machine, under '/var/www/html' , I have an HTML file, and I created an 'onclick' event to invoke a javascript function, in which I wrote a call to run this bash script which is located in my Linux machine under "/" - here it is:
function start_run(pTopoFile, pEmailAddress) {
var childProcess = require('child_process');
var run_command;
run_command = childProcess.exec('/run.sh ' + pTopoFile + ' ' + pEmailAddress, function (error, stdout, stderr) {
if (error) {
console.log(error.stack);
console.log('Error code: '+error.code);
console.log('Signal received: '+error.signal);
}
console.log('Child Process STDOUT: '+stdout);
console.log('Child Process STDERR: '+stderr);
});
ls.on('exit', function (code) {
console.log('Child process exited with exit code '+code);
});
}
When I run the above I get this error:
"ReferenceError: require is not defined"
Which means that even though Node.js was installed properly (as I showed you above), I cannot access its methods from /var/www/html on my Linux machine ...
Can anyone let me know how to link between the great features that node.js has to my scripts?
I hope that I was clear enough with the info I provided...
Thanks,
Tom

How do I debug "Error: spawn ENOENT" on node.js?

When I get the following error:
events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:1000:11)
at Process.ChildProcess._handle.onexit (child_process.js:791:34)
What procedure can I follow to fix it?
Author note: Lots of issues with this error encouraged me to post this question for future references.
Related questions:
using spawn function with NODE_ENV=production
node.js child_process.spawn ENOENT error - only under supervisord
spawn ENOENT node.js error
https://stackoverflow.com/questions/27603713/nodejs-spawn-enoent-error-on-travis-calling-global-npm-package
Node JS - child_process spawn('npm install') in Grunt task results in ENOENT error
Running "foreman" task Fatal error: spawn ENOENT
unhandled error event in node js Error: spawn ENOENT at errnoException (child_process.js:975:11)
Node.js SpookyJS: error executing hello.js
https://stackoverflow.com/questions/26572214/run-grunt-on-a-directory-nodewebkit
Run exe file with Child Process NodeJS
Node: child_process.spawn not working on Java even though it's in the path (ENOENT)
spawn ENOENT error with NodeJS (PYTHON related)
image resizing is not working in node.js (partial.js) (non-installed dependency)
npm install error ENOENT (build dependency problem)
Cannot install node.js - oracle module on Windows 7 (build dependency problem)
Error installing gulp using nodejs on windows (strange case)
NOTE: This error is almost always caused because the command does not exist, because the working directory does not exist, or from a windows-only bug.
I found a particular easy way to get the idea of the root cause of:
Error: spawn ENOENT
The problem of this error is, there is really little information in the error message to tell you where the call site is, i.e. which executable/command is not found, especially when you have a large code base where there are a lot of spawn calls. On the other hand, if we know the exact command that cause the error then we can follow #laconbass' answer to fix the problem.
I found a very easy way to spot which command cause the problem rather than adding event listeners everywhere in your code as suggested in #laconbass' answer. The key idea is to wrap the original spawn call with a wrapper which prints the arguments send to the spawn call.
Here is the wrapper function, put it at the top of the index.js or whatever your server's starting script.
(function() {
var childProcess = require("child_process");
var oldSpawn = childProcess.spawn;
function mySpawn() {
console.log('spawn called');
console.log(arguments);
var result = oldSpawn.apply(this, arguments);
return result;
}
childProcess.spawn = mySpawn;
})();
Then the next time you run your application, before the uncaught exception's message you will see something like that:
spawn called
{ '0': 'hg',
'1': [],
'2':
{ cwd: '/* omitted */',
env: { IP: '0.0.0.0' },
args: [] } }
In this way you can easily know which command actually is executed and then you can find out why nodejs cannot find the executable to fix the problem.
Step 1: Ensure spawn is called the right way
First, review the docs for child_process.spawn( command, args, options ):
Launches a new process with the given command, with command line arguments in args. If omitted, args defaults to an empty Array.
The third argument is used to specify additional options, which defaults to:
{ cwd: undefined, env: process.env }
Use env to specify environment variables that will be visible to the new process, the default is process.env.
Ensure you are not putting any command line arguments in command and the whole spawn call is valid. Proceed to next step.
Step 2: Identify the Event Emitter that emits the error event
Search on your source code for each call to spawn, or child_process.spawn, i.e.
spawn('some-command', [ '--help' ]);
and attach there an event listener for the 'error' event, so you get noticed the exact Event Emitter that is throwing it as 'Unhandled'. After debugging, that handler can be removed.
spawn('some-command', [ '--help' ])
.on('error', function( err ){ throw err })
;
Execute and you should get the file path and line number where your 'error' listener was registered. Something like:
/file/that/registers/the/error/listener.js:29
throw err;
^
Error: spawn ENOENT
at errnoException (child_process.js:1000:11)
at Process.ChildProcess._handle.onexit (child_process.js:791:34)
If the first two lines are still
events.js:72
throw er; // Unhandled 'error' event
do this step again until they are not. You must identify the listener that emits the error before going on next step.
Step 3: Ensure the environment variable $PATH is set
There are two possible scenarios:
You rely on the default spawn behaviour, so child process environment will be the same as process.env.
You are explicity passing an env object to spawn on the options argument.
In both scenarios, you must inspect the PATH key on the environment object that the spawned child process will use.
Example for scenario 1
// inspect the PATH key on process.env
console.log( process.env.PATH );
spawn('some-command', ['--help']);
Example for scenario 2
var env = getEnvKeyValuePairsSomeHow();
// inspect the PATH key on the env object
console.log( env.PATH );
spawn('some-command', ['--help'], { env: env });
The absence of PATH (i.e., it's undefined) will cause spawn to emit the ENOENT error, as it will not be possible to locate any command unless it's an absolute path to the executable file.
When PATH is correctly set, proceed to next step. It should be a directory, or a list of directories. Last case is the usual.
Step 4: Ensure command exists on a directory of those defined in PATH
Spawn may emit the ENOENT error if the filename command (i.e, 'some-command') does not exist in at least one of the directories defined on PATH.
Locate the exact place of command. On most linux distributions, this can be done from a terminal with the which command. It will tell you the absolute path to the executable file (like above), or tell if it's not found.
Example usage of which and its output when a command is found
> which some-command
some-command is /usr/bin/some-command
Example usage of which and its output when a command is not found
> which some-command
bash: type: some-command: not found
miss-installed programs are the most common cause for a not found command. Refer to each command documentation if needed and install it.
When command is a simple script file ensure it's accessible from a directory on the PATH. If it's not, either move it to one or make a link to it.
Once you determine PATH is correctly set and command is accessible from it, you should be able to spawn your child process without spawn ENOENT being thrown.
simply adding shell: true option solved my problem:
incorrect:
const { spawn } = require('child_process');
const child = spawn('dir');
correct:
const { spawn } = require('child_process');
const child = spawn('dir', [], {shell: true});
As #DanielImfeld pointed it, ENOENT will be thrown if you specify "cwd" in the options, but the given directory does not exist.
Windows solution: Replace spawn with node-cross-spawn. For instance like this at the beginning of your app.js:
(function() {
var childProcess = require("child_process");
childProcess.spawn = require('cross-spawn');
})();
For ENOENT on Windows, https://github.com/nodejs/node-v0.x-archive/issues/2318#issuecomment-249355505 fix it.
e.g. replace spawn('npm', ['-v'], {stdio: 'inherit'}) with:
for all node.js version:
spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ['-v'], {stdio: 'inherit'})
for node.js 5.x and later:
spawn('npm', ['-v'], {stdio: 'inherit', shell: true})
#laconbass's answer helped me and is probably most correct.
I came here because I was using spawn incorrectly.
As a simple example:
this is incorrect:
const s = cp.spawn('npm install -D suman', [], {
cwd: root
});
this is incorrect:
const s = cp.spawn('npm', ['install -D suman'], {
cwd: root
});
this is correct:
const s = cp.spawn('npm', ['install','-D','suman'], {
cwd: root
});
however, I recommend doing it this way:
const s = cp.spawn('bash');
s.stdin.end(`cd "${root}" && npm install -D suman`);
s.once('exit', code => {
// exit
});
this is because then the cp.on('exit', fn) event will always fire, as long as bash is installed, otherwise, the cp.on('error', fn) event might fire first, if we use it the first way, if we launch 'npm' directly.
How to research the spawn call raising the error:
Use NODE_DEBUG=child_process, Credits to #karl-richter. Simple, quick, October 2019
Use a wrapper to decorate child_process.spawn, Credits to #jiaji-zhou. Simple, quick, January 2015
Long procedure, credits to #laconbass. Complex, time-cost, December 2014
Known, usual causes
Environment issues
The command executable does not exist within the system (dependency not being installed). see prominc's answer
The command executable does not exist within a directory of those specified by PATH environment variable.
The executable binary was compiled with uncompatible libraries. see danilo-ramirez answer
Windows-only bugs/quirks
'.cmd' extension / shell: true. see li-zheng answer
Administrator permisions. see steve's answer
Wrong spawn('command', ['--argument', 'list'], { cwd, env, ...opts }) usage
Specified working directory (opts.cwd) does not exist ยท see leeroy-brun's answer
Argument list within command String spawn('command --wrong --argument list')
Env vars within command string spawn('ENV_VAR=WRONG command')
Argument list Array specified as String spawn('cmd', '--argument list')
Unset PATH env variable spawn('cmd', [], { env: { variable } } => spawn('cmd', [], { env: { ...process.env, variable } }
There are 2 posible origins for ENOENT:
Code you are writing
Code you depend on
When origin is code you depend on, usual cause is an Environment Issue (or windows quirk)
For anyone who might stumble upon this, if all the other answers do not help and you are on Windows, know that there is currently a big issue with spawn on Windows and the PATHEXT environment variable that can cause certain calls to spawn to not work depending on how the target command is installed.
In my case, I was getting this error thrown due to the necessary dependent system resources not being installed.
More specifically, I have a NodeJS app that is utilizing ImageMagick. Despite having the npm package installed, the core Linux ImageMagick was not installed. I did an apt-get to install ImageMagick and after that all worked great!
Before anyone spends to much time debugging this problem, most of the time it can be resolved by deleting node_modules and reinstalling the packages.
To Install:
If a lockfile exists you might use
yarn install --frozen-lockfile
or
npm ci
respectivly. if not then
yarn install
or
npm i
Are you changing the env option?
Then look at this answer.
I was trying to spawn a node process and TIL that you should spread the existing environment variables when you spawn else you'll loose the PATH environment variable and possibly other important ones.
This was the fix for me:
const nodeProcess = spawn('node', ['--help'], {
env: {
// by default, spawn uses `process.env` for the value of `env`
// you can _add_ to this behavior, by spreading `process.env`
...process.env,
OTHER_ENV_VARIABLE: 'test',
}
});
In case you're experiencing this issue with an application whose source you cannot modify consider invoking it with the environment variable NODE_DEBUG set to child_process, e.g. NODE_DEBUG=child_process yarn test. This will provide you with information which command lines have been invoked in which directory and usually the last detail is the reason for the failure.
I ran into the same problem, but I found a simple way to fix it.
It appears to be spawn() errors if the program has been added to the PATH by the user (e.g. normal system commands work).
To fix this, you can use the which module (npm install --save which):
// Require which and child_process
const which = require('which');
const spawn = require('child_process').spawn;
// Find npm in PATH
const npm = which.sync('npm');
// Execute
const noErrorSpawn = spawn(npm, ['install']);
Use require('child_process').exec instead of spawn for a more specific error message!
for example:
var exec = require('child_process').exec;
var commandStr = 'java -jar something.jar';
exec(commandStr, function(error, stdout, stderr) {
if(error || stderr) console.log(error || stderr);
else console.log(stdout);
});
A case that I found that is not in this list but it's worthy to be added:
On Alpine Linux, Node will error with ENOENT if the executable is not compatible.
Alpine expects binaries with libc. An executable (e.g. chrome as part of chromium) that has been compiled with glibc as a wrapper for system calls, will fail with ENOENT when called by spawn.
Ensure module to be executed is installed or full path to command if it's not a node module
I was also going through this annoying problem while running my test cases, so I tried many ways to get across it. But the way works for me is to run your test runner from the directory which contains your main file which includes your nodejs spawn function something like this:
nodeProcess = spawn('node',params, {cwd: '../../node/', detached: true });
For example, this file name is test.js, so just move to the folder which contains it. In my case, it is test folder like this:
cd root/test/
then from run your test runner in my case its mocha so it will be like this:
mocha test.js
I have wasted my more than one day to figure it out. Enjoy!!
solution in my case
var spawn = require('child_process').spawn;
const isWindows = /^win/.test(process.platform);
spawn(isWindows ? 'twitter-proxy.cmd' : 'twitter-proxy');
spawn(isWindows ? 'http-server.cmd' : 'http-server');
I ran into this problem on Windows, where calling exec and spawn with the exact same command (omitting arguments) worked fine for exec (so I knew my command was on $PATH), but spawn would give ENOENT. Turned out that I just needed to append .exe to the command I was using:
import { exec, spawn } from 'child_process';
// This works fine
exec('p4 changes -s submitted');
// This gives the ENOENT error
spawn('p4');
// But this resolves it
spawn('p4.exe');
// Even works with the arguments now
spawn('p4.exe', ['changes', '-s', 'submitted']);
I had this appear while building gulp-jekyll in Powershell on Windows 11.
nodejs 10 LTS, gulp v3.9.1, ruby 3.1, bundler 2.4.5, jekyll 4.2.2
This line of code here is the cause of the ENOENT issue I had with spawn and bundle.
return cp.spawn('bundle', [
'exec',
'jekyll',
'build',
'--source=app', '--destination=build/development', '--config=_config.yml', '--profile'
], { stdio: 'inherit' })
.on('close', done);
Two errors returned, and troubleshooting should start here. ๐Ÿค“๐Ÿง
events.js:174
throw er; // Unhandled 'error' event
^
Error: spawn bundle ENOENT
The cp.spawn is not handling an error Event, so handling that with a simple console.log() will expose the real error with debug information:
return cp.spawn('bundle', [
'exec',
'jekyll',
'build',
'--source=app', '--destination=build/development', '--config=_config.yml', '--profile'
], { stdio: 'inherit' })
.on('error', (e) => console.log(e))
.on('close', done);
This now provides a lot more information to debug with.
{ Error: spawn bundle ENOENT
errno: 'ENOENT',
code: 'ENOENT',
syscall: 'spawn bundle',
path: 'bundle',
spawnargs:
[ 'exec',
'jekyll',
'build',
'--source=app',
'--destination=build/development',
'--config=_config.yml',
'--profile' ] }
The next step to debug would be using the nodejs 10 LTS documentation for child_process.spawn(command[, args][, options]). As already described above, adding the { shell: true } to the options of spawn is a working solution. This is what solved my problem as well. ๐Ÿ˜Œ
{ stdio: 'inherit', shell: true }
This solution is merely a band-aid and could be refactored to handle all environments, but that is out of scope for how to troubleshoot & debug the spawn ENOENT error on nodejs.
I was getting this error when trying to debug a node.js program from within VS Code editor on a Debian Linux system. I noticed the same thing worked OK on Windows. The solutions previously given here weren't much help because I hadn't written any "spawn" commands. The offending code was presumably written by Microsoft and hidden under the hood of the VS Code program.
Next I noticed that node.js is called node on Windows but on Debian (and presumably on Debian-based systems such as Ubuntu) it's called nodejs. So I created an alias - from a root terminal, I ran
ln -s /usr/bin/nodejs /usr/local/bin/node
and this solved the problem. The same or a similar procedure will presumably work in other cases where your node.js is called nodejs but you're running a program which expects it to be called node, or vice-versa.
If you're on Windows Node.js does some funny business when handling quotes that may result in you issuing a command that you know works from the console, but does not when run in Node. For example the following should work:
spawn('ping', ['"8.8.8.8"'], {});
but fails. There's a fantastically undocumented option windowsVerbatimArguments for handling quotes/similar that seems to do the trick, just be sure to add the following to your opts object:
const opts = {
windowsVerbatimArguments: true
};
and your command should be back in business.
spawn('ping', ['"8.8.8.8"'], { windowsVerbatimArguments: true });
Although it may be an environment path or another issue for some people, I had just installed the Latex Workshop extension for Visual Studio Code on Windows 10 and saw this error when attempting to build/preview the PDF. Running VS Code as Administrator solved the problem for me.
In my case removing node, delete all AppData/Roaming/npm and AppData/Roaming/npm-cache and installing node once again solve the issue.
Recently I also faced similar issue.
Starting the development server...
events.js:174
throw er; // Unhandled 'error' event
^
Error: spawn null ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
at onErrorNT (internal/child_process.js:415:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
Emitted 'error' event at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)
at onErrorNT (internal/child_process.js:415:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
error Command failed with exit code 1.
It was due to having a wrong configuration in .env file for BROWSER. I had BROWSER=null, but it has to be BROWSER=none. Changing that configuration resolved my issue.
Tried all nothing worked , my system has different issue .
The working solution for me is
run command :
npm config set script-shell "C:\Program Files\git\bin\bash.exe"
I got the same error for windows 8.The issue is because of an environment variable of your system path is missing . Add "C:\Windows\System32\" value to your system PATH variable.
Local development on Emulator
Make sure to have the package installed locally. By changing the spawn command with exec i got a more detailed error and found out I didn't install the package. Simply run, to check if the package is present:
brew install imagemagick
Source
There might be a case that you have two package-lock.json files in your project directory (in/out of the main folder), simply delete the one which would have been created accidentally. Delete the build folder and run the server again.

Resources