NodeJS Module "userid" Error: Module version mismatch. Expected 46, got 47 - node.js

I get the following error when trying to start my server.js which requires the module "userid".
module.js:460
return process.dlopen(module, path._makeLong(filename));
^
Error: Module version mismatch. Expected 46, got 47.
at Error (native)
at Object.Module._extensions..node (module.js:460:18)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous> (/root/backend/node_modules/userid/lib/userid.js:2:15)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
How can I solve this issue?

Not sure of the exact meaning of this error but my fix for this is to delete the node_modules directory and reinstall the required modules with npm install.
The above is a solution for this error showing up in a node project which uses locally installed modules. If there are some global modules that are throwing this error then you might have to reinstall those.

I would try upgrading the module version that causes the issue on package.json.

Another reason of this problem is that you have several different node versions installed at your system and you manage them with nvm. If you run node index.js and if you run sudo node index.js it may results in running different node version.
So if you installed your application modules with npm install and then run application with sudo node index.js you will have Module version mismatch error. In such case make sure with nvm that sudo node... run the same version of node as your application expects.
Also, while fixing initial problem you may have problem with nvm described here Can't use NVM from root (or sudo). One of possible solutions to this issue described in Yoo Matsuo's comment.

Related

Cordova - ReferenceError globalThis is not defined

I am following Cordova's Getting Started guide but I'm already stuck at the 2nd step. When I try to create my project by typing cordova create myApp, it fails with the following error message:
C:\Users\foobar\AppData\Roaming\npm\node_modules\cordova\node_modules\queue-microta
sk\index.js:5
? queueMicrotask.bind(globalThis)
^
ReferenceError: globalThis is not defined
at Object.<anonymous> (C:\Users\foobar\AppData\Roaming\npm\node_modules\cordova
\node_modules\queue-microtask\index.js:5:25)
at Module._compile (internal/modules/cjs/loader.js:816:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
at Module.load (internal/modules/cjs/loader.js:685:32)
at Function.Module._load (internal/modules/cjs/loader.js:620:12)
at Module.require (internal/modules/cjs/loader.js:723:19)
at require (internal/modules/cjs/helpers.js:14:16)
at Object.<anonymous> (C:\Users\foobar\AppData\Roaming\npm\node_modules\cordova
\node_modules\run-parallel\index.js:4:24)
at Module._compile (internal/modules/cjs/loader.js:816:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
I guess it's some sort of node or npm version problem. If possible though, I would rather not install a different version of node or npm, because I'm afraid it will break other projects otherwise. My node and npm versions are as follows:
node --version
v11.15.0
npm --version
6.7.0
Just make sure to reinstall the cordova if your node version changed.
And after that, cordova prepare again.
change Node version with Node Version Manager (NVM) to Node version10.X.X.
queueMicrotask don't work with Node version 11.X.X.
https://github.com/feross/queue-microtask/issues/13

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.

Node.js module version mismatch, installed with MacPorts

On OSX, I need to use macports, because I run into issues with Brew. I uninstalled homebrew package manager and tried to get node to work:
I do a clean install of nodejs and npm
sudo port install nodejs npm
Let's just show that there is only npm installed, and no other modules.
$ ls /opt/local/lib/node_modules/
npm
Trying to get a node package working, testing with appdmg
sudo npm install -g appdmg
Now here's the cryptic error. (NOTE: It worked with brew's version of NPM, earlier this morning)
$ appdmg
module.js:460
return process.dlopen(module, path._makeLong(filename));
^
Error: Module version mismatch. Expected 46, got 47.
at Error (native)
at Object.Module._extensions..node (module.js:460:18)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous> (/usr/local/lib/node_modules/appdmg/node_modules/macos-alias/lib/create.js:7:13)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
I'm using 10.8.4 Mountain Lion. I tried with the latest version of node (5.1), and the older version (4.2) and got INVERSE results..
On 5.1, the message reads:
Error: Module version mismatch. Expected 47, got 46.
On 4.2.2 I got
Error: Module version mismatch. Expected 46, got 47.
Which lead me to believe there was some lingering brew version of node. So (after installing node via the node osx packager installation on the main website, not sure if that matters) I ran this uninstall script and it fixed it, thanks to #nicerobot via https://gist.github.com/nicerobot/2697848:
curl -ksO https://gist.githubusercontent.com/nicerobot/2697848/raw/uninstall-node.sh
chmod +x ./uninstall-node.sh
./uninstall-node.sh
rm uninstall-node.sh
npm uninstall lodash
npm install
I've tried many ways but in my case it didn't install the node modules correctly so I uninstalled then installed it back again and it works! Hope it helps.

Installing MEAN Stack: npm -v module.js: 338 throw err; Error: Cannot find module './cache/caching-client.js'

I think I have installed node.js before but never used homebrew to do it. Today I tried to do a walkthrough of an application but got stuck at the very beginning. I am fairly new to programming so I am utterly confused as to why I can't get this to work.
I have tried a lot of things but can't seem to find the answer.
These are the commands I run in order to install the MEAN stack:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
(succesful no errors)
brew install node
(succesfull no errors)
I check if node has installed properly by typing:
node -v
v0.12.4
I then check if npm is installed properly by typing:
npm -v
Here is the error message:
module.js:338
throw err;
^
Error: Cannot find module './cache/caching-client.js'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at /usr/local/lib/node_modules/npm/lib/npm.js:22:24
at Object.<anonymous> (/usr/local/lib/node_modules/npm/lib/npm.js:466:3)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
I have installed node in a different way other than using Homebrew and maybe that is messing things up. Please let me know your thoughts.
What I have tried to do so far is uninstall node and reinstall it using this process:
https://gist.github.com/DanHerbert/9520689
Maybe you've already fixed, but the answer might serve others.
I tried what is in the post that Mario linked to in his comment, but it didn't work. It just so happens that my npm is installed at /Users/USERNAME/.node/bin/, so I added the following line in my .bash_profile file: export PATH="$HOME/.node/bin:$PATH".
In my case it was caused by me installing node with root and later with brew (without root).
As a result brew was not able to override the old npm files upon upgrading.
Manually removing the old node installation worked for me.

Resources