Unable to use native Windows library in NodeJS - node.js

I am trying to write a simple Electron app that uses Windows native notifications. For this use I depend on electron-windows-interactive-notifications.
When I run npm install and after that electron-rebuild on my project I get:
App threw an error during load
Error: The specified module could not be found.
\\?\C:\Users\moro\projects\tw-en-ty\node_modules\electron-windows-interactive-notifications\build\Release\notifications_bindings.node
at Error (native)
at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:173:20)
at Object.Module._extensions..node (module.js:583:18)
at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:173:20)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at bindings (C:\Users\moro\projects\tw-en-ty\node_modules\bindings\bindings.js:76:44)
According to a NodeJS issue it can be a native dependency problem. When I examine notifications_bindings.node by dependencywalker I see following missing direct DLLs (among many missing nested):
Frankly I have no idea what the problem is:
wrong usage of Electron?
wrong usage of electron-windows-interactive-notifications?
problem in NodeRT?
problem in node-gyp?
problem in my environment?
Can you help me move a step closer to the problem resolution?
Thank you very much!
Question was also asked here

Try following:
Install MS Visual Studio first.
npm install --global windows-build-tools run as Administrator
Run electron rebuild .\node_modules\.bin\electron-rebuild.cmd
Alternate method:
cd node_modules\electron-windows-interactive-notifications
node-gyp rebuild --target=1.8.4 --arch=x64 --dist-url=https://atom.io/download/electron where 1.8.4 is electron version

Related

Please try re-compiling or re-installing Nodejs

Have upgraded our server from Ubuntu-18.04LTS to Ubuntu-20.04LTS After OS upgrade when I'm trying to start a nodejs application, but I get the below errors.
2021-11-14 10:48:01.641 - error: server-node-1: '[task-manager]
Error: The module \'/home/blruser/mibs/node_modules/weak/build/Release/weakref.node\'\nwas
compiled against a different Node.js version using\nNODE_MODULE_VERSION 57.
This version of Node.js requires\nNODE_MODULE_VERSION 64.
Please try re-compiling or re-installing\nthe module (for instance, using `npm rebuild` or `npm install`).\n at Object.Module._extensions..node (internal/modules/cjs/loader.js:807:18)\n at Module.load (internal/modules/cjs/loader.js:653:32)\n
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)\n
at Function.Module._load (internal/modules/cjs/loader.js:585:3)\n
at Module.require (internal/modules/cjs/loader.js:692:17)\n
at require (internal/modules/cjs/helpers.js:25:18)\n
at bindings (/home/blruser/mibs/node_modules/bindings/bindings.js:81:44)\n
at Object.<anonymous> (/home/blruser/mibs/node_modules/weak/lib/weak.js:7:35)\n
at Module._compile (internal/modules/cjs/loader.js:778:30)\n
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)\nWARN: uncaughtException be generated\n'
$ nodejs --version
v10.19.0
How do i re-compile without losing any existing application data? Please support. Thanks.
I'm not able to ask more info in comments. But have you tried deleting your node_modules directory and installing afresh using npm install or yarn install? This would not have any impact on your application data, rather just the node modules.
But if it's an electron project or similar, try running npm i -D electron-rebuild, following that do the above mentioned step.

Bcrypt file too short

I am facing an error that causes a crush on my nodejs application. The error is below:
'
Error: /home/*******/nodevenv/******/12/lib/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node: file too short
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1057:18)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/home/outdoor1/nodevenv/prescription_server/12/lib/node_modules/bcrypt/bcrypt.js:6:16)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
internal/modules/cjs/loader.js:1057
return process.dlopen(module, path.toNamespacedPath(filename));
The application is hosted on CPanel-based shared hosting. The application is running for 6 months without error. But for 2 days the application is not running. I re-installed bcrypt. But nothing changes. The application working fine on my local pc.
It looks as if your bcrypt binary has somehow become corrupted.
What was the result of your attempt to reinstall bcrypt? Where there any errors?
The bcrypt repo at https://github.com/kelektiv/node.bcrypt.js notes that it only works on "stable" releases of NodeJS greater than >= 10.0.0 and more importantly, requires recompilation on the host platform on install. If your host does not have a full build environment installed, you will not be able to compile this module locally.
Assuming you are running the correct version of NodeJS, you could try retrieving the repo directly to your host machine, cd to its directory, and run npm install to install its requirements. Chief among these is the node-pre-gyp which is a helper to ease the compilation of native node modules.
Once you've done this, you should be able to run the install command for bcrypt itself, as described in the repo's package.json file: node-pre-gyp install --fallback-to-build. (Note that, depending on how your host is configured, you might need to add npx to the beginning of that command to properly invoke node-pre-gyp, e.g. npx node-pre-gyp install --fallback-to-build)
Note any errors this throws and share them here as an update to your question. I'm guessing that the install fails during compilation and you missed the error messages involved.
Baring everything else, I'd also ask CPanel support since I am sure this is not a unique problem.

Node Module Version Mismatch: Expected 50

I've had this problem where, from a brand new installation of Node and npm, the serial port package won't load with the following error in the Hello World Electron package:
I am on Node version 6.6.0 and NPM version 3.10.7 and OS X 10.11.6.
I looked to see if I was somehow out of date, but looking at this list, I can't find anything that has a module version of 50. Is this a bug?
I have tried npm rebuild, as well as removing modules and reinstalling, but no dice.
Update: even though when I run node -v it prints v6.6.0, running process.versions.node in the web console gives me v6.5.0. What's going on here?
This is a known issue which is caused by the serialport module using native code that is built for a different version of Node. You can read a bit more about addons here, if you're interested; they're just modules written in C/C++ that can interface with Node so the module can interface with the hardware more easily.
The solution proposed by that issue is this:
npm rebuild --runtime=electron --target=1.2.5 --disturl=https://atom.io/download/atom-shell --build-from-source
If you've not already installed electron-rebuild, that might be helpful to ensure that the rebuilding process works correctly:
npm install --save-dev electron-rebuild
even though when I run node -v it prints v6.6.0, running process.versions.node in the web console gives me v6.5.0. What's going on here?
Electron uses its own version of Node that isn't connected to your system Node installation (see the homepage to view the Node version that the latest Electron uses, or use process.versions.node, like you did in the question).
You could try an older version (perhaps 1.1.0, which uses Chrome 50?) in case that is the cause of the issue.
In my case the error was:
App threw an error during load
Error: Module version mismatch. Expected 50, got 48.
at Error (native)
at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:173:20)
at Object.Module._extensions..node (module.js:583:18)
at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:173:20)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/myapp/node_modules/sqlite3/lib/sqlite3.js:4:15)
After rebuilding error was fixed:
npm install --save-dev electron-rebuild
npm rebuild --runtime=electron --target=1.4.3 --disturl=https://atom.io/download/atom-shell --build-from-source

Module version mismatch. Expected 49, got 48

I am using Electron module mdns and I am getting this error
A JavaScript error occurred in the main process
Uncaught Exception:
Error: Module version mismatch. Expected 49, got 48.
at Error (native)
at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:167:20)
at Object.Module._extensions..node (module.js:568:18)
at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:167:20)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/ingsaurabh/dp/node_modules/mdns/lib/dns_sd.js:24:20)
Uninstalled node module and reinstalled, but not working
npm rebuild --runtime=electron --target=1.3.4 --disturl=https://atom.io/download/atom-shell --abi=50
in your case it should be 49
Since mdns contains a native Node module you must rebuild it to target your version of Electron, there are a couple of ways to do this. I'd suggest using the electron-rebuild approach.
This is well-know problem when when upgrading node version. For example: you are using Node for example version 5. You add some libraries inside your project, build and run that. All your libraries will be compiled under node version 5.
And then you upgrade your node for example to version 6. And then you run some commands that using node, for example npm run test. The problem is here: you use newer node version for running libraries that compiled by older node.
Solving this is easy by 2 following commands:
rm -rf node_modules // force remove node_modules directory
npm install // install again all libraries. Libraries will be compiled again with node version 6
So this is a general method apply for all javascript frameworks, not only electron ...

cannot find module 'config-chain'

This is my first post, so forgive me for formatting issues. I was following this mean.io tutorial: https://www.youtube.com/watch?v=0aMNWYpG5sk. It basically gets you to the point where you can locally access the default web app. I was able to do so successfully.The video then suggests to run>
mean package myTheme
I received this error...
C:\Users\****\myApp>mean package myTheme
module.js:339
throw err;
^
Error: Cannot find module 'config-chain'
at Function.Module._resolveFilename (module.js:337:15)
at Function.Module._load (module.js:287:25)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous> (C:\Users\****\AppData\Roaming\npm\node_modules\mean-cli\node_modules\npm\lib\config\core.js:2:10)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)
I'm running npm 2.14.7 and node v4.2.3(video uses 4.2.2) on Win 10. I had previously tried this on node 5.3 and received the same error. I also tried cleaning cache & updating npm, bower, and gulp.
I found C:\Users****\myApp\node_modules\config-chain. Do I need to change something here?
Any help would be greatly appreciated. If I need to provide more information, just ask. Thanks!
I guess something was wrong with mean-cli.
I reran:
npm install -g mean-cli
npm install (inside project folder)
My issue was resolved. Hope this helps someone else.
I just removed and re-installed and everything worked. Go figure. I also had to use sudo because I'm on a mac.
sudo npm install -g ember-cli#2.5
The problem is when you install config-chain it installs in your project directory node_modules but cordova add browser is looking in global modules. This is what I did, went outside the directory and ran npm install -g config-chain That resolved this module and asked for more do the same thing for all modules it complains and you should be good.

Resources