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.
Related
I need to work with an app based on ionic framework v1 and Cordova 7.1, but there is the following problem with Node when running Cordova:
$ cordova -v
/node_modules/cordova/node_modules/npm-normalize-package-bin/index.js:3
const {join, basename} = require('path')
^
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:387:25)
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)
at require (internal/module.js:20:19)
at Object.<anonymous> (node_modules/cordova/node_modules/read-package-json/read-json.js:14:27)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
I installed Cordova with this command:
npm install -g cordova#7.1.0
The project requires the following versions which are installed on my machine:
node -v
v5.12.0
npm -v
3.8.6
ionic -v
1.7.15
grunt --version
grunt-cli v0.1.13
grunt v0.4.5
bower -v
1.8.4
plugman -v
2.0.0
Does anyone have a clue where the problem is? I'm glad for any help.
The problem is that nodejs v5.x doesn't support destructuring, which is used in the line
const {join, basename} = require('path')
You can read more about supported js features in nodejs here, https://node.green/#ES2015-syntax-destructuring--declarations
Cordova depends on "init-package-json" which in turn depends on "read-package-json: 1 || 2".
Now there's been an update to "read-package-json" some months ago which introduces a new dependency to "npm-normalize-package-bin". This package makes use of a syntax construct that's apparently supported not before node 6.0.0.
So, if updating node is not an option (which is recommended, since node 5 - 8 is end-of-life), you may install this (also rather outdated) cordova locally (inside the project folder) and overwrite the read-package-json dependency there by npm i read-package-json#2.0.13.
Edit: Call cordova via npx: npx cordova -v
Thank you all for your helpful inputs to better understand the cause.
Unfortunately, updating node was not an option. In the end, I compared my Cordova installation with a teammate who does not have this problem. The only difference was that his 'cordova/node_modules/npm-normalize-package-bin' was not present where the error is triggered. So I deleted this package from my system to solve the problem.
Maybe this will help somebody else.
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
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.
In Linux Mint, I've installed node and used it to install typescript. With a working typescript installation, tsc --version should return the version number. In my case, nothing is returned at all.
When I run which tsc the result is /usr/local/bin/tsc.
When I run cat /usr/local/bin/tsc the result is:
#!/usr/bin/env node
require('../lib/tsc.js')
When I run find /usr/local -name 'tsc*' the result is:
/usr/local/bin/tsc
/usr/local/lib/node_modules/typescript/bin/tsc
/usr/local/lib/node_modules/typescript/lib/tsc.js
Does that look correct? If so, then any ideas on what else to look at would be appreciated?
Note I also tried running /usr/local/lib/node_modules/typescript/bin/tsc --version and got the same result ie nothing.
In my case on Ubuntu 16.04 the problem was because of I performed sudo apt-get install node-typescript, which delivered me broken tsc. After removing it via apt-get remove and then installing as recommended with npm install -g typescript, it worked fine.
Maybe this will help someone.
I discovered that running node --version returns nothing (but shouldn't) however nodejs --version works (the result being v0.10.25). Reinstalling node didn't fix this. I don't know why this would be the case, as I think I followed the recommended installation procedure.
However, editing file /usr/local/bin/tsc and changing the line:
#!/usr/bin/env node
to
#!/usr/bin/env nodejs
seemed to work. Now tsc --version returns message TS6029: Version 1.6.2 and I'm getting .js files generated when I run make.
I was getting the following error in Ubuntu 16.04.6 :
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module 'typescript/tsc.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:690:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/usr/bin/tsc:2:1)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
Running : npm install -g typescript didn't resolved the issue.
So, I had to install the latest version of node i.e nvm install <nvm version>
Then with npm install , it fixed the issue.
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.