Getting Error: spawn ./node_modules/.bin/grunt ENOENT when running grunt - node.js

I have a project that is started in development by
yarn start
It runs a index.js that starts a grunt process and get this error:
$ yarn start
yarn start v0.23.2
$ node ./development
grunt_arguments [ '--force', '--notify', '--verbose', '--debug', '--stack' ]
=======================================
Open http://localhost:8000 to start developing
events.js:141
throw er; // Unhandled 'error' event
^
Error: spawn ./node_modules/.bin/grunt ENOENT
at exports._errnoException (util.js:907:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:189:32)
at onErrorNT (internal/child_process.js:355:16)
at nextTickCallbackWith2Args (node.js:458:9)
at process._tickCallback (node.js:372:17)
at Function.Module.runMain (module.js:443:11)
at startup (node.js:139:18)
at node.js:990:3
error Command failed with exit code 1.
No idea what can it be. Environment is:
Win10
Running with MINGW64

I usually monkey patch child_process to help me debug that kind of issues. Add something like this in the beginning of your index.js file:
const util = require('util')
const childProcess = require("child_process");
const originalSpawn = childProcess.spawn;
childProcess.spawn = function() {
console.trace('SPAWN');
console.log('ARGS');
console.log(util.inspect(arguments, false, null)); // showHidden = false, depth = null
return originalSpawn.apply(this, arguments);
};
If your run, childProcess.spawn('ls', ['-lh', '/usr']) you will see something like:
Trace: SPAWN
at Object.childProcess.spawn (repl:2:9)
at myFunction (repl:2:14)
at repl:1:1
at REPLServer.defaultEval (repl.js:164:27)
at bound (domain.js:250:14)
at REPLServer.runBound [as eval] (domain.js:263:12)
at REPLServer.<anonymous> (repl.js:392:12)
at emitOne (events.js:82:20)
at REPLServer.emit (events.js:169:7)
at REPLServer.Interface._onLine (readline.js:210:10)
ARGS
{ '0': 'ls', '1': [ '-lh', '/usr' ] }
Maybe after running it you can update your question with the new information.

Related

nodejs graphviz: graph.output() converter giving error during DOT to PNG conversion

graphviz = require('graphviz');
var g = graphviz.digraph("G");
// Add node (ID: Hello)
var n1 = g.addNode( "Hello", {"color" : "blue"} );
n1.set( "style", "filled" );
// // Add node (ID: World)
g.addNode( "World" );
// // Add edge between the two nodes
var e = g.addEdge( n1, "World" );
e.set( "color", "red" );
// // Print the dot script
console.log( g.to_dot() );
g.setGraphVizPath("/usr/local/bin")
g.output("png", "test.png")
Error
node:events:490
throw er; // Unhandled 'error' event
^
Error: spawn dot ENOENT
at ChildProcess._handle.onexit (node:internal/child_process:285:19)
at onErrorNT (node:internal/child_process:483:16)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on ChildProcess instance at:
at ChildProcess._handle.onexit (node:internal/child_process:291:12)
at onErrorNT (node:internal/child_process:483:16)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn dot',
path: 'dot',
spawnargs: [ '-Tpng', '-otest.png' ]
}
Tried upgrading and downgrading node version, tried using rendererDot module for conversion, nothing worked. DOT file is not getting converted to SVG/PNG.

Can't get a ws WebSocket server to run on Vite dev server. WS_ERR_INVALID_CLOSE_CODE

I'm trying to get a WebSocket server to run on top of Vite's built-in dev server. I'm grabbing the httpServer instance directly from Vite and asking ws to listen on it, and it gives a fatal error which I can't find mentioned anywhere on the web.
I tried manually listening for "upgrade" events on Vite's httpServer and calling ws.Server.handleUpgrade() myself, but that gives me the same exact error. If I run all the code and simply leave off the call to handleUpgrade() then it will stop giving any errors. The error definitely seems to come from handleUpgrade(), I just have no clue what the error means or how to fix it.
It should be noted that I'm using SvelteKit and TypeScript in this project. This is my vite.config.ts file:
import type { UserConfig } from 'vite';
import { sveltekit } from '#sveltejs/kit/vite';
import { WebSocketServer } from "ws";
const config: UserConfig = {
plugins: [
sveltekit(),
{
name: "webSocketServer",
configureServer: (viteDevServer: any) => {
const webSocketServer = new WebSocketServer({
server: viteDevServer.httpServer
});
}
}
]
};
export default config;
This is the error I get when running the npm run dev command:
node:events:491
throw er; // Unhandled 'error' event
^
RangeError: Invalid WebSocket frame: invalid status code 16001
at Receiver.controlMessage (C:\Users\MSJim\Documents\programming-data\visual-studio-code\frontends\sveltekit-websockets-chat\node_modules\ws\lib\receiver.js:566:18)
at Receiver.getData (C:\Users\MSJim\Documents\programming-data\visual-studio-code\frontends\sveltekit-websockets-chat\node_modules\ws\lib\receiver.js:442:42)
at Receiver.startLoop (C:\Users\MSJim\Documents\programming-data\visual-studio-code\frontends\sveltekit-websockets-chat\node_modules\ws\lib\receiver.js:158:22)
at Receiver._write (C:\Users\MSJim\Documents\programming-data\visual-studio-code\frontends\sveltekit-websockets-chat\node_modules\ws\lib\receiver.js:84:10)
at writeOrBuffer (node:internal/streams/writable:392:12)
at _write (node:internal/streams/writable:333:10)
at Writable.write (node:internal/streams/writable:337:10)
at Socket.socketOnData (C:\Users\MSJim\Documents\programming-data\visual-studio-code\frontends\sveltekit-websockets-chat\node_modules\ws\lib\websocket.js:1274:35)
at Socket.emit (node:events:525:35)
at addChunk (node:internal/streams/readable:324:12)
Emitted 'error' event on WebSocket instance at:
at Receiver.receiverOnError (C:\Users\MSJim\Documents\programming-data\visual-studio-code\frontends\sveltekit-websockets-chat\node_modules\ws\lib\websocket.js:1160:13)
at Receiver.emit (node:events:513:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
code: 'WS_ERR_INVALID_CLOSE_CODE',
[Symbol(status-code)]: 1002
}
Where it reads invalid status code 16001, the 16001 seems to change every time I run it. I have gotten 39338, 38329, and 29320 when running it 3 additional times.

How to get PostgreSQL dump database file using Node JS

I tried to generate postgresql dump file using Node JS. SO, I used secure-backup library to generate pg-dump file encrypted. I add this package in my project and I configured .pem file also. When I execute this file it's throwing some error. but I couldn't understand what type error is throwing and how to fix it I don't know. Any one give some suggestion how to resolve this issue to generate pg dump file using Node JS otherwise different library used to generate pg dump file.
CODE
let secureBackup = require('secure-backup');
let pgHandler = require('secure-backup/lib/handlers/pg')
console.log('hi')
let backup = secureBackup({
pubKeyPath: 'C:/Users/DELL/Desktop/Twilio_Phone/cert.pem', // path to your public key
outputPath: 'C:/Users/DELL/Desktop/DB_Dump', // where to output your encrypted backup
compress: true, // enable compression (gzip)
handler: pgHandler({
user: 'postgres',
password: '*****',
database: '****'
})
})
backup() // can be invoked directly
// or used with a cron-job module like node-schedule
Error
events.js:292
throw er; // Unhandled 'error' event
^
Error: spawn pg_dump ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)
at onErrorNT (internal/child_process.js:465:16)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
Emitted 'error' event on ChildProcess instance at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
at onErrorNT (internal/child_process.js:465:16)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
errno: -4058,
code: 'ENOENT',
syscall: 'spawn pg_dump',
path: 'pg_dump',
spawnargs: [ '-U', 'postgres', 'HP', 'hummapi' ]
}

Node.js child_process has no access to global modules

I have installed a npm packages globally in my Kubuntu 19.04
$ npm install -g cordova
/home/username/.npm-global/bin/cordova -> /home/username/.npm-global/lib/node_modules/cordova/bin/cordova
+ cordova#9.0.0
updated 1 package in 7.299s
I can access it from shell
$ cordova -v
9.0.0 (cordova-lib#9.0.1)
But I can't access it from a simple node script with spawn:
const { spawn } = require( 'child_process' );
const cmd = spawn( 'cordova', [ '-v' ] );
cmd.stdout.on( 'data', data => {
console.log( `stdout: ${data}` );
} );
Running it results in the following:
$ node test1.js
events.js:298
throw er; // Unhandled 'error' event
^
Error: spawn cordova ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
at onErrorNT (internal/child_process.js:467:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
Emitted 'error' event on ChildProcess instance at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:273:12)
at onErrorNT (internal/child_process.js:467:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn cordova',
path: 'cordova',
spawnargs: [ '-v' ]
}
But when using absolute path:
const { spawn } = require( 'child_process' );
const cmd = spawn( '/home/username/.npm-global/bin/cordova', [ '-v' ] );
cmd.stdout.on( 'data', data => {
console.log( `stdout: ${data}` );
} );
I get the expected result:
$ node test1.js
stdout: 9.0.0 (cordova-lib#9.0.1)
My script above is just a testcase, since I have problem to add/run cordova specific stuff in vue-cli-plugin-cordova and quasar. I tracked it down, that the global path is the problem.
Update
I think I found the problem, but not sure how to solve it. When setting /bin/bash as shell, it works:
cmd = spawn('cordova', ['-v'], {
shell: '/bin/bash'
});
Not sure, why this is needed and why the packages vue-cli-plugin-cordova and quasar don't do it.
Ok, after hours of research and tryouts, I have uninstalled node, installed nvm and latest node, set
nvm use --delete-prefix v13.7.0 --silent >> /dev/null
and added this to ~/.bashrc
and now everything works
how I solve my error, I changed the environment variable PATH: to C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;{plus program paths}
which is
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files\nodejs
in my PATH

getting error 'assetmanager.process is not a function' while trying to start node server

I am trying to run MEAN stack, I am trying to start Node server by running node server command,
`TypeError: assetmanager.process is not a function
at configureApp (C:\Users\Harsh\first\node_modules\meanio\lib\core_modules\module\aggregation.js:401:29)
at Consumer.Dependable.runAction (C:\Users\Harsh\first\node_modules\lazy-dependable\index.js:73:22)
at Consumer.Dependable.fire (C:\Users\Harsh\first\node_modules\lazy-dependable\index.js:70:53)
at Consumer.onResolved (C:\Users\Harsh\first\node_modules\lazy-dependable\index.js:120:8)
at Consumer.Dependable.resolve (C:\Users\Harsh\first\node_modules\lazy-dependable\index.js:56:10)
at Meanio.Container.notifyResolved (C:\Users\Harsh\first\node_modules\lazy-dependable\index.js:209:7)
at Dependency.onResolved (C:\Users\Harsh\first\node_modules\lazy-dependable\index.js:105:18)
at Dependency.Dependable.resolve (C:\Users\Harsh\first\node_modules\lazy-dependable\index.js:56:10)
at Meanio.Container.register (C:\Users\Harsh\first\node_modules\lazy-dependable\index.js:167:5)
at C:\Users\Harsh\first\node_modules\meanio\lib\core_modules\db\index.js:101:20
at open (C:\Users\Harsh\first\node_modules\mongoose\lib\connection.js:488:17)
at NativeConnection.Connection.onOpen (C:\Users\Harsh\first\node_modules\mongoose\lib\connection.js:498:5)
at C:\Users\Harsh\first\node_modules\mongoose\lib\connection.js:457:10
at C:\Users\Harsh\first\node_modules\mongoose\lib\drivers\node-mongodb-native\connection.js:60:5
at C:\Users\Harsh\first\node_modules\mongodb\lib\db.js:229:5
at connectHandler (C:\Users\Harsh\first\node_modules\mongodb\lib\server.js:279:7)
at g (events.js:260:16)
at emitOne (events.js:77:13)
at emit (events.js:169:7)
at C:\Users\Harsh\first\node_modules\mongodb-core\lib\topologies\server.js:409:23
at C:\Users\Harsh\first\node_modules\mongodb-core\lib\topologies\server.js:778:13
at Callbacks.emit (C:\Users\Harsh\first\node_modules\mongodb-core\lib\topologies\server.js:95:3)
C:\Users\Harsh\first\node_modules\mongodb\lib\server.js:282
process.nextTick(function() { throw err; })
^
TypeError: assetmanager.process is not a function
at configureApp (C:\Users\Harsh\first\node_modules\meanio\lib\core_modules\module\aggregation.js:401:29)
at Consumer.Dependable.runAction (C:\Users\Harsh\first\node_modules\lazy-dependable\index.js:73:22)
at Consumer.Dependable.fire (C:\Users\Harsh\first\node_modules\lazy-dependable\index.js:70:53)
at Consumer.onResolved (C:\Users\Harsh\first\node_modules\lazy-dependable\index.js:120:8)
at Consumer.Dependable.resolve (C:\Users\Harsh\first\node_modules\lazy-dependable\index.js:56:10)
at Meanio.Container.notifyResolved (C:\Users\Harsh\first\node_modules\lazy-dependable\index.js:209:7)
at Dependency.onResolved (C:\Users\Harsh\first\node_modules\lazy-dependable\index.js:105:18)
at Dependency.Dependable.resolve (C:\Users\Harsh\first\node_modules\lazy-dependable\index.js:56:10)
at Meanio.Container.register (C:\Users\Harsh\first\node_modules\lazy-dependable\index.js:167:5)
at C:\Users\Harsh\first\node_modules\meanio\lib\core_modules\db\index.js:101:20
at open (C:\Users\Harsh\first\node_modules\mongoose\lib\connection.js:488:17)
at NativeConnection.Connection.onOpen (C:\Users\Harsh\first\node_modules\mongoose\lib\connection.js:498:5)
at C:\Users\Harsh\first\node_modules\mongoose\lib\connection.js:457:10
at C:\Users\Harsh\first\node_modules\mongoose\lib\drivers\node-mongodb-native\connection.js:60:5
at C:\Users\Harsh\first\node_modules\mongodb\lib\db.js:229:5
at connectHandler (C:\Users\Harsh\first\node_modules\mongodb\lib\server.js:279:7)
at g (events.js:260:16)
at emitOne (events.js:77:13)
at emit (events.js:169:7)
at C:\Users\Harsh\first\node_modules\mongodb-core\lib\topologies\server.js:409:23
at C:\Users\Harsh\first\node_modules\mongodb-core\lib\topologies\server.js:778:13
at Callbacks.emit (C:\Users\Harsh\first\node_modules\mongodb-core\lib\topologies\server.js:95:3)
Also used gulp command still same error, where am I going wrong??
Had a similar error when there was an issue with the git clone. Re-clone the repository and then run on your console:
git clone https://github.com/meanjs/mean.git myprojectname
npm install
bower install
The install processes will take a little while but running gulp after this should work.

Resources