Node Module Version Mismatch: Expected 50 - node.js

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

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.

cannot use native node module in electron-forge app

I am trying to use pkcs11js in an electron app created with electron-forge using webpack template.
But I got the error
Error: C:\ws-p\electron-test\.webpack\main\349a63bd9833f80e7879a5bbfb2a4af2.node is not a valid Win32 application.
←[90m at Object.Module._extensions..node (internal/modules/cjs/loader.js:1122:18)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:928:32)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:769:14)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)←[39m
←[90m at internal/main/run_main_module.js:17:47←[39m
There are lots of questions asked around but none of the provided solutions/answers worked for me so far.
None of these worked out:
remove & reinstall node_modules
use electron-rebuild (although electron-forge uses this internally)
use node-gyp rebuild --target=13.1.0 --arch=x64 --dist-url=https://electronjs.org/headers manually for the package
Npm steps defined in electron docs
Environment:
Windows 10 Pro
Node 14.16.1
electron: 13.1.0
electron-rebuild: 2.3.5
electron-forge: 6.0.0-beta.57
pkcs11js: 1.2.4
You should use the Electron Forge Webpack template which has better support for native modules.
There is currently an open issue for this functionality caused by the outdated/unmaintained #marshallofsound/webpack-asset-relocator-loader which caters for native modules via Webpack. I'm currently working on a PR to fix this but in the meantime you can use my updated fork.
None of the solutions on the web worked for me. What worked is defining electron-gyp output folder as home before electron-rebuild or with electron-forge right after/before dependencies install.
In a terminal:
Windows:
set HOME=C:\Users\YourUser\.electron-gyp
npm i
npm run start <# which resolves to electron-forge start #>
Unix:
$ export HOME=~/.electron-gyp
$ npm i
$ npm run start # which resolves to electron-forge start
I hope it helps to someone

Node - Difference between npm -v and the real version

Using Mac terminal and trying to run a Gatsby site, I am running into a problem.
As far as I found out, it is becase of an old version of Node. Particularly, "Node 6.* doesn't natively support async operations".
Just out for curiosity, the error I get when installing the app is:
async sendEvents() {
^^^^^^^^^^
SyntaxError: Unexpected identifier
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/usr/local/lib/node_modules/gatsby-cli/node_modules/gatsby-telemetry/lib/index.js:3:19)
So it looks like a matter of just upgrading.
Here comes the tricky part.
When I run npm -v, I get this output: 6.12.0. Ok, all looks coherent. I get the error because I have version 6.
Then I go brew upgrade npm and check out the output: Error: npm 12.11.1 already installed.
Any comments?
I think you should get the latest stable version of node instead ([Download Node])1, because the brew upgrade npm command only upgrades npm. When you download the .dmg file for Node, you get the latest stable version for Node and NPM.
Then, the npm -v just returns the version of npm you currently have installed on your machine and the real version (will assume node -v) is the version of node js running on your machine.
NPM is the Node Package Manager. It is not the same as Node itself. To get the current version of Node that's running, node -v will tell you.
Node and npm are individual modules if you will. You do get npm installed with NodeJS, But they can be installed separately as well.
So you can end up with two different versions of each.
In addition, you can have node and npm installed locally. Or you could have node and npm installed with homebrew. (in a cellar) In which case you end up with two separate installs. So you may need to check which install is being actively used.
In your case, check what node version you have first.
node --version
and then you can go from there. If it matches npm version, check what path is linked when you type npm or node.
You may potentially use which command to see which installation is currently being used.
which node
above command should give you path, copy that path
and run
ls -l [copied-path]
output from ls -l should give you a path that will tell you which installation is being used.
If above path does not point to brew path, I believe you can run brew link to change that path
brew link node

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 'readable-stream' when using npm

I installed nodejs and am trying to use npm on my Windows machine. I downloaded all the files from nodejs website. I tried to install the latest 4.4.2 version or 5.10.1 version, but I always got error Cannot find module 'readable-stream' when I tried to run commands using npm.
C:\Users\Ealon>node -v
v5.10.1
C:\Users\Ealon>npm -v
module.js:341
throw err;
^
Error: Cannot find module 'readable-stream'
at Function.Module._resolveFilename (module.js:339:15)
at Function.Module._load (module.js:290:25)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (C:\Users\Ealon\AppData\Roaming\npm\node_modules\npm\node
modules\npmlog\node_modules\are-we-there-yet\index.js:2:14)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
I tried to reinstall it again and again, still could not fix this problem. And the answers in another similar question do not help because I always got error when I tried to run any command using npm. Any help is appreciated. Thanks!
Judging from the line C:\Users\Ealon\AppData\Roaming\npm\node_modules\npm\node
modules\npmlog\node_modules\are-we-there-yet\index.js:2:14 in the stack trace, I believe that you had a global installation of npm which internally had a dependency on are-we-there-yet, which I confirmed has a dependency on readable-stream.
The global installation of npm appears to have been borked, and are-we-there-yet couldn't resolve access to the readable-stream module for some reason (bad install?).
This wasn't getting fixed by re-installing node, which by default installs npm into program files (path similar to C:\Program Files\nodejs\node_modules\npm). I think the global version was getting run, but the version inside program files should be getting run, so wiping out the global installation of npm should hopefully resolve the issue.
I somehow fixed this issue by upgrading npm in Intellij IDEA.
But I still want an expnalation why that problem in my question happened. I will not mark this as the answer.
No need to uninstall node js. When I tried to update my node version, I got this issue & resolved the the same by following below step -
Go to control panel --> uninstall Programs --> select node.js
and click repair.
Had this issue on a Mac. I cloned a project multiple times to handle different branches in parallel. Only one of my cloned repos started having this same issue when I ran npm start. I deleted the repo, cloned it again and nom was running fine again in that repo. Doesn't sound like a global issue to me. No idea what went wrong.

Resources