Loading an external node module with require on Electron during runtime - node.js

I'm trying to build a tool that requires the user to load a node bundle JS file during runtime and evaluate some of the exported functions.
Currently on the local Dev environment this works fine using (do note path is a user path)
delete require.cache[path];
let inst = await import(path);
if (!inst.default) {
console.warn(`Unable to load core from ${path}`)
return false;
}
But once packaged I'm getting the following error,
[112207:0221/164632.255945:ERROR:sandbox_linux.cc(376)] InitializeSandbox() called with multiple threads in process gpu-process.
16:46:32.350 › Checking for update
16:46:35.212 › Update for version 4.5.0 is not available (latest version: 4.5.0, downgrade is disallowed).
16:46:35.213 › checkForUpdatesAndNotify called, downloadPromise is null
(node:112169) UnhandledPromiseRejectionWarning: Error: Cannot find module '/home/ukr/Documents/work/<file>.js'
at t (/tmp/.mount_GradieAhn7PR/resources/app.asar/dist/main/main.js:2:536067)
at /tmp/.mount_GradieAhn7PR/resources/app.asar/dist/main/main.js:2:519883
at IpcMainImpl.<anonymous> (/tmp/.mount_GradieAhn7PR/resources/app.asar/dist/main/main.js:2:519841)
(Use `electron-react-boilerplate --trace-warnings ...` to show where the warning was created)
(node:112169) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
^C^C
This is a quick internal devtool and requires no dependency loading nor security. How can I archive this? Thanks in advance!

Related

Can I ignore unhandledRejection warning of node JS while deployment with CI Jenkins?

I am getting below warning message while building my react js project using CI
npm build fails with below message:
npm run build command contains --trace-warnings. But it has not trace exact location of warning.
(node:179) UnhandledPromiseRejectionWarning: Failed to compile server
at emitUnhandledRejectionWarning (internal/process/promises.js:170:15)
at processPromiseRejections (internal/process/promises.js:247:11)
at processTicksAndRejections (internal/process/task_queues.js:96:32) (node:179)
UnhandledPromiseRejectionWarning: Unhandled promise rejection. This
error originated either by throwing inside of an async function
without a catch block, or by rejecting a promise which was not handled
with .catch(). To terminate the node process on unhandled promise
rejection, use the CLI flag --unhandled-rejections=strict (see
https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode).
(rejection id: 1) (node:179) [DEP0018] DeprecationWarning: Unhandled
promise rejections are deprecated. In the future, promise rejections
that are not handled will terminate the Node.js process with a
non-zero exit code.
at emitDeprecationWarning (internal/process/promises.js:180:11)
at processPromiseRejections (internal/process/promises.js:249:13)
at processTicksAndRejections (internal/process/task_queues.js:96:32)
Is there a way I can ignore the warning during this process as I cannot find out the cause of this warning and not able to fix this.
Node version 10.16.3
npm version. 6.9.0
Using Jenkins for CI.

Getting error while running "ng serve" for my first angular application

Message&trace:
Generating browser application bundles (phase: building)...(node:5312) UnhandledPromiseRejectionWarning: TypeError: MessagePort was found in message but not listed in transferList
at new Worker (internal/worker.js:170:17)
at SassWorkerImplementation.createWorker (C:\Users\shail\iacademiaApp1\node_modules\#angular-devkit\build-angular\src\sass\sass-service.js:96:24)
at SassWorkerImplementation.render (C:\Users\shail\iacademiaApp1\node_modules\#angular-devkit\build-angular\src\sass\sass-service.js:62:40)
at Object.loader (C:\Users\shail\iacademiaApp1\node_modules\sass-loader\dist\index.js:46:3)
(node:5312) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:5312) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:5312) UnhandledPromiseRejectionWarning: TypeError: MessagePort was found in message but not listed in transferList
at new Worker (internal/worker.js:170:17)
at SassWorkerImplementation.createWorker (C:\Users\shail\iacademiaApp1\node_modules\#angular-devkit\build-angular\src\sass\sass-service.js:96:24)
at SassWorkerImplementation.render (C:\Users\shail\iacademiaApp1\node_modules\#angular-devkit\build-angular\src\sass\sass-service.js:62:40)
at Object.loader (C:\Users\shail\iacademiaApp1\node_modules\sass-loader\dist\index.js:46:3)
(node:5312) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
/ Generating browser application bundles (phase: building)...
The latest version of the Angular CLI (12.0.1) does not support Node below version 12.20.
Solution
Update your version of Node to the latest stable version
You should pick the version marked LTS, which at the time of writing is in the 14.x.x range.
Workaround
Only do this if you for some reason are completely unable to update your Node version
Add node-sass to your project devDependencies until you are able to update your version of node.
npm i -save-dev node-sass
yarn add -D node-sass
You should be careful with this workaround, as node-sass is going to be deprecated soon.
Please try this:
ng update #angular/cli
npm install

How to see stacktrace / cause of an error in Jest?

I'm trying to debug a nodeJS app.
I have some code which causes an error, a variable is undefined.
When I run the code normally, the error is very clear and easy to find:
without jest:
➜ server git:(dc/build) ✗ node test/runner.js
/Users/dc/dev/exiteer/xbot/server/src/mup/Story.js:24
Logger.logObj('loaded story', {name: doc.name})
^
ReferenceError: doc is not defined
at Story.reload (/Users/dc/dev/exiteer/xbot/server/src/mup/Story.js:24:42)
at Game.reload (/Users/dc/dev/exiteer/xbot/server/src/mup/Game.js:48:16)
at Object.<anonymous> (/Users/dc/dev/exiteer/xbot/server/test/runner.js:4:10)
Sweet, I can fix it.
Now, Jest has some nice tooling for writing tests so I thought I'd try that.
But the errors are seemingly impossible to track down:
➜ server git:(dc/build) ✗ npm run jest
> cbg#0.1.0 jest /Users/dc/dev/exiteer/xbot/server
> jest
PASS src/index.test.js
(node:23114) UnhandledPromiseRejectionWarning: ReferenceError: doc is not defined
(Use `node --trace-warnings ...` to show where the warning was created)
(node:23114) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:23114) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
FAIL src/mup/Actor.test.js
● Console
console.log
actors undefined
at Object.<anonymous> (src/mup/Actor.test.js:9:13)
● Game.js › can load a story
expect(received).toHaveLength(expected)
Matcher error: received value must have a length property whose value must be a number
Received has value: undefined
8 |
9 | console.log('actors', game.story.room.name.actors)
> 10 | expect(game.story.room.actors).toHaveLength(1);
| ^
11 | const actor = game.story.room.actors[0]
12 | const reply = actor.sayTo('hi')
13 | expect(reply).toBe('hi back from Sid')
at Object.<anonymous> (src/mup/Actor.test.js:10:36)
This tells me where my tests failed, but I'd prefer to know where the actual error is. Tests aren't the end goal here, a working app is.
Googling around I found and tried this but it gives the same error message.
node --trace-warnings node_modules/.bin/jest --no-cache
➜ server git:(dc/build) ✗ npm run test
> cbg#0.1.0 test /Users/dc/dev/exiteer/xbot/server
> node --trace-warnings node_modules/.bin/jest --no-cache
(node:23263) UnhandledPromiseRejectionWarning: ReferenceError: doc is not defined
at emitUnhandledRejectionWarning (internal/process/promises.js:151:15)
at processPromiseRejections (internal/process/promises.js:211:11)
at processTicksAndRejections (internal/process/task_queues.js:98:32)
(node:23263) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
which gives a tiny bit more info but an
at emitUnhandledRejectionWarning (internal/process/promises.js:151:15)
at processPromiseRejections (internal/process/promises.js:211:11)
at processTicksAndRejections (internal/process/task_queues.js:98:32)
This is not very helpful for debugging my code.
Also Jest seems to swallow all console.log as if it's doing the best to make debugging as painful as possible. When your environment doesn't even log, its a real WTF moment.
This was a bug in Node.js or Jest depending on your perspective - I fixed this a few months ago.
It happens because Jest throws errors in JavaScript coming from a different realm - so instanceof Error fails. You can see my PR here.
There is a workaround if you are forced to use old versions of Node or Jest here:
process.on('unhandledRejection', (reason) => {
console.log(reason); // log the reason including the stack trace
throw e;
});
We added this hook in Node 1.3 so it should be safe to use in virtually all Node code.

React-Admin: `make` commands are failing

I'm trying to get my local environment working after cloning the react-admin repo.
I'm tried to run make install and make build as guided by the docs, but these won't work for me.
I install make globally. And yarn, npm and nodejs are all up-to-date. I'm on Windows-10 using Visual Studio Code with PowerShell terminal.This is what I get...
make install returns:
make i info Invoking install target
(node:7316) UnhandledPromiseRejectionWarning: undefined
(node:7316) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:7316) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
make × ERR not found: make-package.json
make build returns:
(node:9000) UnhandledPromiseRejectionWarning: undefined
(node:9000) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:9000) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
make × ERR not found: make-##
I really want to get started on my ra fix branch so any help would be appreciated.Hopefully, it's just a simple mistake on my end.
It's interesting to note that make is primarily a utility tool for the unix env.
Therefore running make commands is not a direct process in windows environment.
NMAKE is the official windows alternative that will help you achieve the same.

Cordova Plugin: support for subdirectories is deprecated

If I am trying to run the unit tests of any plugin (e.g cordova-plugin-geolocation), I have to add the tests subdirectory of the plugin in my project. While adding the tests subdirectory of a remote project, I am getting a support for subdirectories is deprecated and will be removed in Cordova#7 error.
The command I am trying to use to add the tests is
cordova plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation#:/tests.
If fetch does not support adding subdirectories, How can someone add the unit tests of a plugin in his project?
The error and the stack trace is shown below:
(node:57857) UnhandledPromiseRejectionWarning: CordovaError: --fetch does not support subdirectories
at Object.fetchPlugin [as fetch] (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/fetch.js:71:37)
at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/plugin/add.js:98:40
at _fulfilled (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/q/q.js:787:54)
at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/q/q.js:816:30
at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/q/q.js:749:13)
at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/q/q.js:810:14
at flush (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/q/q.js:108:17)
at process._tickCallback (internal/process/next_tick.js:61:11)
at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
at startup (internal/bootstrap/node.js:266:19)
(node:57857) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:57857) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Adding the –-nofetch flag, does not resolve the issue either. Is cloning the project and using the location of the test directory to add to the project, the only option I have?
I am using cordova version 8.

Resources