Error: Module version mismatch - without removing node_modules - node.js

When trying to start up my application using node app.js I'm getting this error:
lucas#XYZ:~/app/lucas$ node app.js
module.js:583
return process.dlopen(module, path._makeLong(filename));
^
Error: Module version mismatch. Expected 48, got 57.
at Error (native)
at Object.Module._extensions..node (module.js:583:18)
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> (/home/lucas/app/lucas/node_modules/canvas/lib/bindings.js:3:18)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
When I type in node -v I get v6.5.0
As this website shows, this corresponds to version 48, so where the 57 is coming from?
I know the default solution is deleting node_modules but I'd like to understand what's going on here and try to avoid that, and any other similar approaches that involve reinstalling all modules etc. Question is more about understanding the actual problem.
EDIT: If you're curious whats in that bindings.js file this is all that's inside:
'use strict';
module.exports = require('../build/Release/canvas.node');

Simply put Node 6.x is trying to open a native module built for Node 8.x.
Based on the traceback, it's the canvas module – you've somehow ended up with a newer native module for canvas in your node_modules than the Node you're running with. (One way this can happen is by using nvm, n or other node version manager.)
You don't necessarily have to nuke all of node_modules to fix this (though it doesn't hurt, and if you have a project that doesn't survive nuking node_modules, that's a problem in itself) – you could try renaming node_modules/canvas to node_modules/canvas.backup or something and running npm install (or yarn install) again (with the correct Node version active) and it should download/recompile the native module for canvas as it's reinstalling the now "missing" canvas.

Related

Node "Error: Cannot find module 'node:process'" when using global fastify-cli (mac)

I'm setting up a new mac dev machine, and have gotten node, npm, and nvm installed. All seems fine within a single project directory. However, when trying to install and use fastify-cli, I'm receiving an error:
internal/modules/cjs/loader.js:892
throw err;
^
Error: Cannot find module 'node:process'
Require stack:
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/marked-terminal/index.cjs
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/blessed-contrib/lib/widget/markdown.js
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/blessed-contrib/index.js
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/docs.js
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/cli.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
at Function.Module._load (internal/modules/cjs/loader.js:745:27)
at Module.require (internal/modules/cjs/loader.js:961:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object.<anonymous> (/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/marked-terminal/index.cjs:3:17)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Module.require (internal/modules/cjs/loader.js:961:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/marked-terminal/index.cjs',
'/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/blessed-contrib/lib/widget/markdown.js',
'/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/blessed-contrib/index.js',
'/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/docs.js',
'/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/cli.js'
]
}
Steps to reproduce:
$ npm install --global fastify-cli (succeeds)
$ fastify generate myproject (also produces above error)
$ fastify (also produces above error)
This likely doesn't have much to do with fastify. It seems to me that the global package is not finding Node for some reason, but I may be wrong.
I'm using zshell
I've got xcode installed
I've upgraded the version of node i'm using
I'm able to start a fastify app from the app directory directly/without using the generator
Any thoughts?
I fixed the error following the answer in this GitHub issue reply
node internal syntax (e.g.: node:<core_module_name>) is not supported by Node.js 14.16.0
The CLI needs node version >= 14.19
Steps:
Upgrade node using nvm to 14.9.0 (the last lts in 14.x).
Set default version 14.9.0 or above.
you need to run
npm i #types/node
I solved it by switching the current user to a root user.
If you are using a Mac, try to switch to a root user account and do the same thing again.
I assigned my previous account as 'administrator' under system preferences, but this won't solve the issue. The problem was perfectly solved when I switched to my primary account.
Hope this could help!

npm run gulp primordials not defined

I'm trying to run npm run gulp and I'm coming up with this primordials is not defined error (I have also added the npm-shrinkwrap.json file as suggested which gets updated after running npm install but it doesn't fix my primordials is not define error):
> gulp-tutorial#1.0.0 gulp
> gulp
fs.js:47
} = primordials;
^
ReferenceError: primordials is not defined
at fs.js:47:5
at req_ (/Applications/MAMP/htdocs/wordpress/wp-content/themes/theming-main/node_modules/natives/index.js:143:24)
at Object.req [as require] (/Applications/MAMP/htdocs/wordpress/wp-content/themes/theming-main/node_modules/natives/index.js:55:10)
at Object.<anonymous> (/Applications/MAMP/htdocs/wordpress/wp-content/themes/theming-main/node_modules/vinyl-fs/node_modules/graceful-fs/fs.js:1:37)
at Module._compile (node:internal/modules/cjs/loader:1095:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1147:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
Node.js v17.0.1
Any suggestions 🙌 ?
Primordials are used by Node.js internal modules and are not accessible to end user scripts. (That's their entire point for existing. Otherwise, you could modify Object.prototype and end up affecting Node.js internals, causing weird crashes and things like that.)
The module that is giving you this error is the natives module. The page for the package says:
This module relies on Node.js's internals and will break at some point. Do not use it, and update to graceful-fs#4.x.
Sounds like it's at that point where it's broken. Use npm ls natives to find out what's using it. (You might need to be in the /Applications/MAMP/htdocs/wordpress/wp-content/themes/theming-main directory when you run the command.) From there, you can try to figure out how to get rid of it.
Another possibility would be to try downgrading to an earlier version of Node.js to see if it works with that version.
The problem was with the versions not matching up. I also had 2 NodeJS installation paths and that was throwing things off.
I uninstalled them all, started from the beginning and used brew to reinstall.
Then checked that the versions were all compatible.
I also had to install node-sass and referred to this compatibility table to get the correct version - https://github.com/sass/node-sass#node-version-support-policy
Now its working and I can get on developing :) As of today Im running Node v17.0.1 Npm v8.1.0 Gulp cli v2.3.0

A module does not compile in a newer node.js version, any workarounds?

my open-source project depends on a lemmatization module —
https://github.com/grachev/node-lemmer
— which needs to be compiled before it can run.
After updating to a newer version of node.js I can't run this module, because it needs to be re-compiled. Usually this was done when I simply did npm install node-lemmer however it is now not available in npm and I don't know how to compile it under that new node version and why I have to do it at all...
I tried running npm rebuild but it does not recompile – too many errors. The issues folder of that project on GitHub has the issue up already but there's no fix for it...
What could I do about it? Why do I need to recompile this module when I install a new version of node? Is there a workaround? Could I "trick" node or that module so it doesn't need to recompile? Or maybe it's possible to compile it manually?
...
Some mode details:
I used to run my project on node 0.8.3 vesion and then switched to the new 8.8.0 version. Now when I try to run my project under the new node version it doesn't start giving the following error:
module.js:641
return process.dlopen(module, path._makeLong(filename));
^
Error: Module did not self-register.
at Object.Module._extensions..node (module.js:641:18)
at Module.load (module.js:531:32)
at tryModuleLoad (module.js:494:12)
at Function.Module._load (module.js:486:3)
at Module.require (module.js:556:17)
at require (internal/module.js:11:18)
at Object.<anonymous>
(/path-to-my-project/node_modules/node-lemmer/lib/node-lemmer.js:1:82)
at Module._compile (module.js:612:30)
at Object.Module._extensions..js (module.js:623:10)
at Module.load (module.js:531:32)
which is an error I've seen before because my module could not be compiled.
my project is https://github.com/noduslabs/infranodus in case it helps to see the source code.

Electron app throw version Module version mismatch error. Expected 49, got 48

I try running electron app, after updating node to 6.3.0.
I update all dependencies to latest and when i try running the app, it throw following error,
/Volumes/Shankar_Drive/Work/git/safe_launcher/testApp/node_modules/bindings/bindings.js:83
throw e
^
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 bindings (/Volumes/Shankar_Drive/Work/git/safe_launcher/testApp/node_modules/bindings/bindings.js:76:44)
I tried npm cache clean && npm install and also removing node_modules folder and run npm install no use in that.
I even tried electron-rebuild on specific modules say ('ffi' and 'ref'), but no use
Environment I run these:
node 6.3.0
npm 3.8.6
electron-prebuild 1.3.1
Please someone help me out. Thanks in advance.
I have just created a shell script to deal with this specifically for Electron. Why? Because removing node_modules doesn't always work and so many people have this problem. A simple rebuild without special flags won't necessarily work either.
This script takes the target abi version as the first argument and detects your Electron version automatically. You can optionally pass your electron version as the second argument but 99% of the time the "Expected" abi version should be enough.
Here it is: https://github.com/TomAshley303/electron-abi-fix
Simply drop it into your project directory and run: sh electron-abi-fix.sh 49
(If 49 is the expected abi version in your error). You can also pass the Electron version as a second argument but shouldn't need to.

Issue with gulp trying to run an example - 'The super constructor to `inherits` must not be null or undefined.'

I'm trying to run an example, but I'm getting the following error when I try to gulp. I'm pretty new to node, so any direction or help would be very appreciated. The install went without any issues, seemingly.
$ nvm exec 4.2.2 gulp
Running node v4.2.2 (npm v2.14.7)
util.js:756
throw new TypeError('The super constructor to `inherits` must not ' +
^
TypeError: The super constructor to `inherits` must not be null or undefined.
at Object.exports.inherits (util.js:756:11)
at Object.<anonymous> ([working directory path]/node_modules/browser-sync/node_modules/http-proxy/lib/http-proxy/index.js:108:17)
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)
at require (module.js:385:17)
at Object.<anonymous> ([working directory path]/node_modules/browser-sync/node_modules/http-proxy/lib/http-proxy.js:4:17)
at Module._compile (module.js:435:26)
It seems this issue has come up in different contexts before but was unanswered:
1) Mean.io application is throwing error with forever
2) https://github.com/rajaraodv/rabbitpubsub/issues/4
Seems to be a fairly recent issue and it seems to not have to do with http-proxy.
Turned out to be a problem with an older version of browser-sync. Once that was updated, this started to work.
Try an older version of Node. The example's package.json specifies Node 0.10 in the engines section, which suggests the initial code may have been written for that version.

Resources