Node js Error: spawn node ENOENT with grunt - javascript

I'm trying to run a simple grunt task with protractor but everytime I receive an error on the console. I am using grunt with forever utility and placed various breakpoints take narrow down the error causing code. The selenium server created a session for the test cases but the system generates the following error while trying to execute the test suite.
Error: spawn node ENOENT
at exports._errnoException (util.js:746:11)
at Process.ChildProcess._handle.onexit (child_process.js:1046:32)
at child_process.js:1137:20
at process._tickCallback (node.js:355:11)
[launcher] Process exited with error code 1
I cleared all the node processes and still the problem persisted. Any ideas?
Gruntfile.js
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
protractor: {
all: {
options: {
configFile: "conf.js",
keepAlive: true
}
}
}
});
grunt.loadNpmTasks('grunt-protractor-runner');
grunt.registerTask('test', protractor);
};
my_spec.js
this.foreverMonitor = function(port){
forever.list(false, function(){
var child = new (forever.Monitor)('app.js', {
killTree: true,
silent: true
...
});
child.start();
forever.startServer(child);
});
}
var port = 5000;
foreverMonitor(port);
browser.getSession().then(function(sess){
console.log(sess.id);
});
describe('..', function(){
it('..', expect());
});

Related

NodeJS can not go to the folder up to execute the command from child_process.spawn

To start WebPack (which is in the parent folder) I use Gulp, but as soon as I try to go to the parent folder in the path, I get an error.
Gulp
var spawn = require('child_process').spawn;
gulp.task('_Scada2', function (done) {
spawn('webpack', [], { cwd: '../../Scada.Web/' })
.on('close', done);
});
get an error
[14:20:47] '_Scada2' errored after 4.47 ms
[14:20:47] Error: spawn webpack ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:229:19)
at onErrorNT (internal/child_process.js:406:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
Процесс завершен с кодом 1.
Try __dirname + '../../Scada.Web/'

Error: spawn node ENOENT

I'm working on my Electron app with Express server and when I build it with electron-packager, I get an error.
Uncaught Exception:
Error: spawn node ENOENT
at exports._errnoException (util.js:1024:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:192:19)
at onErrorNT (internal/child_process.js:374:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
at Function.Module.runMain (module.js:607:11)
at startup (bootstrap_node.js:167:16)
at bootstrap_node.js:589:3
here is my main.js where child process is called
const cp = require('child_process');
let instance = cp.spawn('node',['./app.js']);
var electron = require('electron');
var browserWindow = electron.BrowserWindow;
var app = electron.app;
app.on('ready', function(){
// appWindow
var appWindow;
appWindow = new browserWindow({
width:1120,
height:620,
webPreferences: {
plugins: true
},
icon: __dirname + '/public/icon/icon.png'
});
appWindow.loadURL('file://' +__dirname + '/public/prva.html');
//appWindow.webContents.openDevTools();
});
// close app after all windows are closed
app.on('window-all-closed', () => {
app.quit()
})
Does anyone know solution for this error?
You most likely have a problem with your app.js script. You should hook onto some of the event listeners to understand what's really going on. There's an error, exit, close, disconnect, and message events you can listen for. You can also hook onto a number of other things such as the stdin, stdout, stderr as well. Checkout the documentation for the different events, hook onto all of them and output some information and you should be able to track down the issue.
You should also check to see if your express services runs properly directly from the command line rather than from within this Electron app. If it does then you've likely got a path wrong. This could be either that child_process cannot find the "node" application to run, or it can't find your startup script. In either case, you can use the path module to build up the correct path.

spawn ls ENOENT when watched file is modified

I am learning Node.js via the book Node.js the Right Way. I am trying to run the following example to watch changes to a file called target.txt that resides in the the same directory as the .js file.
"use strict";
const
fs = require('fs'),
spawn = require('child_process').spawn,
filename = process.argv[2];
if (!filename) {
throw Error("A file to watch must be specified!");
}
fs.watch(filename, function () {
let ls = spawn('ls', ['-lh', filename]);
ls.stdout.pipe(process.stdout);
});
console.log("Now watching " + filename + " for changes...");
I get the following error when I change the text file and save it:
events.js:160
throw er; // Unhandled 'error' event
^
Error: spawn ls ENOENT
at exports._errnoException (util.js:1018:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
at onErrorNT (internal/child_process.js:367:16)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
Node.js version: v6.11.0
IDE: Visual Studio Code 1.13.1
OS: Windows 10 64x
There's no ls on Windows, you should use dir instead.
However, that's not an executable. To run .bat and .cmd files you can:
Spawn cmd.exe and pass those files as arguments:
require('child_process').spawn('cmd', ['/c', 'dir']);
Use spawn with the shell option set to true:
require('child_process').spawn('dir', [], { shell: true });
Use exec instead of spawn:
require('child_process').exec('dir', (err, stdout, stderr) => { ... });
For more on that, take a look at this section in the official docs.
EDIT:
I'm not sure I understood you question in the comment correctly, but if you go for the second option, for example, you code will look like this:
...
fs.watch(filename, function () {
let dir = spawn('dir', [filename], { shell: true });
dir.stdout.pipe(process.stdout);
});
...
Please, keep in mind you may need to adjust this code slightly. I'm writing all this from memory as I don't have access to a Windows machine right now, so I can't test it myself.

Gulp Browser-Sync task error

Im trying to change from Grunt to Gulp now, and need a static server (gulp-connect doesn't provide a keepalive option, have no Idea why)
But I constantly get this error whenever trying to run the gulp browser-sync task:
[gulp] Using gulpfile C:\Users\Fernando\Projects\renovaintra.template\gulpfile.js
[gulp] Starting 'browser-sync'...
[gulp] Finished 'browser-sync' after 2.81 ms
[BS] Server running. Use this URL: http://192.168.1.102:3002
[BS] Serving files from: C:\Users\Fernando\Projects\renovaintra.template/public/
[BS] Watching files...
events.js:72
throw er; // Unhandled 'error' event
^
Error: This socket is closed.
at Socket._write (net.js:637:19)
at doWrite (_stream_writable.js:226:10)
at writeOrBuffer (_stream_writable.js:216:5)
at Socket.Writable.write (_stream_writable.js:183:11)
at Socket.write (net.js:615:40)
at Socket.Writable.end (_stream_writable.js:341:10)
at Socket.end (net.js:396:31)
at Static.gzip (C:\Users\Fernando\Projects\renovaintra.template\node_modules\browser-sync\node_modules\socket.io\lib\static.js:207:14)
at ready (C:\Users\Fernando\Projects\renovaintra.template\node_modules\browser-sync\node_modules\socket.io\lib\static.js:370:14)
at C:\Users\Fernando\Projects\renovaintra.template\node_modules\browser-sync\node_modules\socket.io\lib\static.js:103:9
And here it is my gulp task:
__location = './public/';
gulp.task('browser-sync', function() {
browserSync.init([__location + '*.html'], {
server: {
baseDir: __location
}
});
});

Node js : spawn throws error in linux

The following is my code, It works in windows with out error but when I setup my project in server (linux) it is not working and throws error
var spawn = require('child_process').spawn,
javaCmd= spawn('java', ['-cp',__dirname+'/Java/jdk1.7.0_45/lib/dom4j.jar;'+__dirname+'/Java/jdk1.7.0_45/lib/geronimo-stax-api_1.0_spec-1.0.1.jar;'+__dirname+'/Java/jdk1.7.0_45/lib/gson-2.2.4.jar;'+__dirname+'/Java/jdk1.7.0_45/lib/mysql-connector-java-5.1.6.jar;'+__dirname+'/Java/jdk1.7.0_45/lib/ooxml-schemas-1.0.jar;'+__dirname+'/Java/jdk1.7.0_45/lib/poi-3.9-20121203.jar;'+__dirname+'/Java/jdk1.7.0_45/lib/poi-ooxml-3.9.jar;'+__dirname+'/Java/jdk1.7.0_45/lib/xmlbeans-2.5.0.jar;'+__dirname+'/Java/jdk1.7.0_45/lib/xmlbeans-xmlpublic-2.6.0.jar;'+__dirname+'/Java/jdk1.7.0_45/lib/excelreader.jar', 'astral.excelreader.Main', catid, id,target_path]);
javaCmd.stdout.on('data', function (data) {
console.log(data);
});
javaCmd.stdout.on('close', function(code) {
console.log(code);
});
javaCmd.stderr.on('data', function (data) {
console.log(data);
});
Following is the error
events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:980:11)
at Process.ChildProcess._handle.onexit (child_process.js:771:34)
Anybody know its reason? I did n't set any other path for java. I tried to set using $ vi ~/.bash_profile but I got the following response
-bash: $: command not found
Anybody know how to set path in linux server

Categories