Node - Difference between npm -v and the real version - node.js

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

Related

npm does not support Node.js v8.17.0 WSL2

So I've been getting the below error. I know the ideal answer is to update but to update, would be a very substantial amount of work at this point, and we're only using this to compile our code locally. It would seem others have gotten this working within my company without issue, but I'm the only one on Windows 11 trying to do this through WSL (version 2 to be specific in the VM). Basically, this happens whenever I run an npm command. Whether it's npm install or npm -v, it comes up every single time.
I am using nvm v0.39.0 and Node v8.17.0 so the npm version "should be" 6.13.4 according to nodejs.org. I have installed Node through nvm using nvm install 8 and nvm alias default 8. I also have 12 installed but have ensured I'm switched to 8. I can't find anything
When I nvm use 12 or nvm use --lts, I obviously get new errors that I'd have to work through (a big amount of work mostly in QA for clients, not going to get into extensive detail). Can anyone think of a way around this?
It's not like an app where it's constantly running and we need the latest and greatest. It's only for compiling code during the development and deployment process.
npm does not support Node.js v8.17.0
You should probably upgrade to a newer version of the node as we
can't make any promises that npm will work with this version.
You can find the latest version at https://nodejs.org/
/home/<user>/.nvm/versions/node/v8.17.0/lib/node_modules/npm/lib/npm.js:32
#unloaded = false
^
SyntaxError: Invalid or unexpected token
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:617:28)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at module.exports (/home/<user>/.nvm/versions/node/v8.17.0/lib/node_modules/npm/lib/cli.js:22:15)
UPDATE
I tried to duplicate the issue on my Linux PopOS machine, and these are the steps I took to replicate it (So maybe not Windows specific, but maybe Linux, since the other environment was in WSL 2 Ubuntu dist?):
Install nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
Install the versions we support and set the default:
nvm install 8
nvm alias default 8
nvm install 12
nvm use 8
npm login --registry=https://example.com/ (not disclosing this on stackoverflow)
At this point I did an npm -v and it returned v6.13.4.
Install a few things we know we'll need for our projects, in each version:
nvm use 8 && npm install -g npm && npm install -g grunt-cli gulp-cli
It broke and started giving the error again after the above command.

npm giving error on Mac Big Sur, not able to install or run

I just installed node with the below commands and here are the outputs
$ brew install node
$ node -v
v9.4.0
$ command -v node
/usr/local/bin/node
$ ls -l /usr/local/bin/node
-rwxr-xr-x 1 icyborg wheel 35697312 Jan 14 2018 /usr/local/bin/node
after running
$ brew upgrade node
Warning: node 15.9.0 already installed
but when I do
$ node -v
v9.4.0
now when I am trying to do
npm -v
It gives this error,
TypeError: Cannot destructure property `stat` of 'undefined' or 'null'.
at Object.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/#npmcli/node-gyp/lib/index.js:2:29)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/#npmcli/run-script/lib/run-script-pkg.js:4:55)
at Module._compile (module.js:660:30)
/usr/local/lib/node_modules/npm/node_modules/#npmcli/config/lib/index.js:163
throw new Error('call config.load() before reading values')
^
It is difficult to understand this error. May I know what can be the issue? I thought npm comes with node and I can't find any way to install it independently on mac.
SOLUTION - it seems node wasn't LinkedIn. I ran
brew link --overwrite node
and it is working now
Node.js 9 has been unsupported for about 3 years. The error you're seeing is very likely due to using an old Node.js with a new npm.
When I run brew info node, it says 15.2.0 is available. So, either something went wrong with your brew installation, or else you have an old version of Node.js somewhere else in your path (or as an alias) that runs instead of the version installed by brew.
Run command -v node to find out what Node.js is being executed. If it doesn't start with /usr/local/bin/node, then that's your problem. If it is /usr/local/bin/node, run ls -l /usr/local/bin/node to make sure it's a link to something in /usr/local/Cellar/node. If it's not, that's your problem... (EDIT #2: ...and as OP notes in a comment, brew link --overwrite node fixed that for them. So anyone else reading this can try that.)
EDIT #1: Since you've updated the question with the above information: It looks like you probably installed Node.js 9 around 3 years ago with the regular installer and not brew. Again, you can probably avoid all these headaches by uninstalling with brew and reinstalling with nvm as mentioned in the next paragraph.
In general, if you're installing Node.js on a personal computer and not on a server, I'd recommend uninstalling the brew version and installing with a per-user version manager. nvm is a solid choice:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash

Deploy Meteor app to Synology armv7: There is an issue with `node-fibers`

I've spent a couple of days trying to run a build app from Meteor on my Synology ds213j (Armv7, 512MB ram).
I keep encountering the following error
## There is an issue with `node-fibers` ##
`/volume1/homes/user/app/bundle/programs/server/node_modules/fibers/bin/linux-arm-57/fibers.node` is missing.
Try running this to fix the issue: /volume1/homes/user/.nvm/versions/node/v8.11.2/bin/node /volume1/homes/user/app/bundle/programs/server/node_modules/fibers/build
Error: /volume1/homes/user/app/bundle/programs/server/node_modules/fibers/bin/linux-arm-57/fibers.node: internal error
at Object.Module._extensions..node (module.js:681:18)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/volume1/homes/user/app/bundle/programs/server/node_modules/fibers/fibers.js:13:39)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
/volume1/homes/user/app/bundle/programs/server/node_modules/fibers/fibers.js:22
throw new Error('Missing binary. See message above.');
^
Error: Missing binary. See message above.
at Object.<anonymous> (/volume1/homes/user/app/bundle/programs/server/node_modules/fibers/fibers.js:22:9)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/volume1/homes/user/app/bundle/programs/server/boot.js:1:75)
at Module._compile (module.js:652:30)
BUT, fibers.node actually EXIST!
What I did before:
build meteor app meteor build --server-only --architecture os.linux.x86_32
on the /program/server folder npm install --production
npm install fibers
What I tried to fix it:
go to /programs/server/ and run npm install fibers (and reinstall)
installing from source following the instructions on
https://www.npmjs.com/package/fibers
my meteor app uses Node 8.11.2 but the only node version available for synology is 8.9.4. Removed it and manually installed the 8.11.2
build an default meteor app to check if is my app giving problems.
Nothing worked so far and I have no idea what to do next.
I suspect the problem is that fibers is built for linux-arm-57 and I suppose I need arm-7I?
There is something I can do to make this work?
Thanks!
In the following I describe the way you correctly deploy your app to an ARMv7 device. By doing so I will highlight important steps that may often be cause of errors. I hope your problem will solve by reproducing these steps.
1. Build your production app
Make sure the app starts, runs and all your tests pass on local.
Get your current development version of node. Note, that it varies, depending on the meteor version your project uses. Note: The meteor guide on custom deployment underlines the importance of a matching node version.
$ cd ~/path/to/meteor-project
$ meteor node -v
v8.9.4 # this example uses Meteor 1.6.1 which uses node 8.9.4
build your production app using the build command (I adapted your specs a bit here).
$ cd ~/path/to/meteor-project
$ meteor npm install --production
$ meteor build ../build/deployment-test --server-only --architecture os.linux.x86_32
2. Prepare your target device' environment
Meteor builds are also Node.js applications. Your device will require an ARMv7 build of Node.js. The easiest way to do that is to use the install script from nodesource (open in new tab to view the script).
$ curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
$ sudo apt-get install -y nodejs
Note, that official node installation guide also points out, that "To compile and install native addons from npm you may also need to install build tools". You will need this, because fibers or bcrypt are such native addons.
$ sudo apt-get install -y build-essential
Verify your installed node version
$ node -v
v8.11.4 # but we need v8.9.4
The easiest way to get the correct version of node, that exactly matches your development version, is to use the npm n package.
$ sudo npm install -g n
$ sudo n 8.9.4
$ # ... installs target version
$ node -v
v8.9.4 # if this is still the old version just restart the shell
if you need help on this, read this github issue thread
finally install mongodb >= 2.6 (important!) on your target device (not covered in this answer).
3. Install your production app on the target device
copy / move / upload your build archive to your target device
extract your deployment bundle
$ cd ~/path/to/deploymentapp
$ tar -xvzf ./meteor-project.tar.gz # extracts all content into a folder named 'bundle'
install npm dependencies on target system
$ cd bundle/programs/server/
$ npm install --production
if you have replicated all the above steps the npm packages (and espeically the native packages, such as fibers or bcrypt) should be installed here without any errors. Now go back to bundle/ and start the app:
$ cd ../../
$ MONGO_URL=mongodb://yourmongodbcredentials node main.js
I hope by replicating this guide you will find a solution to your problem.
Added for SEO reasons: This guide shows how to deploy a Meteor app on a Raspberry PI with ARMv7 architecture and Raspbian (32 bit) installed. It can also be used as a foundation for other ARMv7 devices, such as OP's Synology.

Error: Failed to load gRPC binary module

I have been following the tutorial: https://docs.particle.io/tutorials/integrations/google-cloud-platform/
trying to send humidity and temperature data from a Particle Photon to Google Cloud Datastore. The high level architecture is as follows:
where data is sent from the Photon to Particle Cloud to Google Cloud (Pub/Sub) and to Google Datastore with Node.js as an intermediary.
Everything works to Pub/Sub but as I try to activate the node script (calling: node tutorial.js) I receive errors.
When calling node tutorial.js I receive:
$ node tutorial.js
Authenticating with Google Cloud...
/home/lennart/node_modules/grpc/src/grpc_extension.js:55
throw error;
^
Error: Failed to load gRPC binary module because it was not installed for the current system
Expected directory: node-v64-linux-x64-glibc
Found: [node-v57-linux-x64-glibc]
This problem can often be fixed by running "npm rebuild" on the current system
Original error: Cannot find module '/home/lennart/node_modules/grpc/src/node/extension_binary/node-v64-linux-x64-glibc/grpc_node.node'
at Object.<anonymous> (/home/lennart/node_modules/grpc/src/grpc_extension.js:53:17)
at Module._compile (internal/modules/cjs/loader.js:702:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)
at Module.require (internal/modules/cjs/loader.js:650:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (/home/lennart/node_modules/grpc/src/client_interceptors.js:145:12)
at Module._compile (internal/modules/cjs/loader.js:702:30)
I tried npm rebuild as suggested in the error message, but this made no change.
Current versions of different packages:
$ npm -v
6.1.0
$ node -v
v10.4.1
$ openssl version -v
OpenSSL 1.0.2o 27 Mar 2018
Previously I had problems with OpenSSL and Node compatability, which could be traced from: Error undefined symbol: SSL_library_init. Node v10.4.1 was installed which then seemed to cause the above error.
I finally solved this by doing the following:
Making sure the right version of Node was installed:
npm install --target=10.0.0 --target_platform=linux --target_arch=x64
Copying the folder node-v64-linux-x64-glibc to two other folders (see below) apart from where it initially had been installed (/home/lennart/Desktop/Cloud/google-cloud-datastore-tutorial-master/node_modules/grpc/src/node/extension_binary) via the previous command.
/home/lennart/node_modules/#google-cloud/video-intelligence/node_modules/grpc/src/node/extension_binary
/home/lennart/node_modules/grpc/src/node/extension_binary
This could probably be solved in a more elegant way, but at least it worked.
I am experiencing the same issue with node:10-alpine base image in Docker.
The solution that works for me is running additionally npm rebuild on the container's entry point.
FROM node:10-alpine
WORKDIR /app
COPY package*.json .
RUN npm install
COPY . .
CMD npm rebuild && npm run migrate:run
Probably running the same npm rebuild should resolve the issue locally, or, perhaps this is a problem with npm as it cannot fetch the proper binary timely.
Would yarn make a difference?
Please check the NODE&NPM version of reguler user and SUPER USER NODE&NPM versions are same.
For me a simple yarn --force did it, once I used nvm to switch to the proper node.js version. I had originally done yarn with the wrong version.

Can't Install Browser Sync on Mac

Thank you to anyone taking the time to help me. Let me start off by saying I'm very new to the coding world so I'm still trying to get my head around using terminal on a mac. So I have both jsnode and npm succesfully installed on my system. When I've installed browser-sync it seems to install fine. However, when I run browser-sync --version I get the following error.
Last login: Fri Jan 19 01:08:36 on ttys000
Marks-MacBook-Pro:~ Brent$ npm install -g browser-sync
/Users/Brent/.npm-global/bin/browser-sync -> /Users/Brent/.npm-global/lib/node_modules/browser-sync/dist/bin.js
+ browser-sync#2.23.5
updated 1 package in 6.436s
Marks-MacBook-Pro:~ Brent$ browser-sync --version
module.js:540
throw err;
^
Error: Cannot find module 'dev-ip'
at Function.Module._resolveFilename (module.js:538:15)
at Function.Module._load (module.js:468:25)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/usr/local/lib/node_modules/browser-sync/dist/utils.js:3:13)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
Marks-MacBook-Pro:~ Brent$
Also I don't know if this helps but I will show the PATH (not that I know what that means but I'm trying to read up):
Marks-MacBook-Pro:~ Brent$ echo $PATH
/Library/Frameworks/Python.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
Marks-MacBook-Pro:~ Brent$
Also, is there any harm in installing something that is already installed? As in, doesn't it just replace the files that already exist? The reason why I'm asking is that I have uninstalled/reinstalled jsnode and npm multiple times to the point where I feel like I might just need to try and uninstall everything again and try a new method. Just to reiterate, my main question is how to get browser-sync to install properly! Thank you.
I finally resolved this issue by using node version manager (nvm) instead of installing nodejs straight up. Here is a step by step guide to isntall nvm:
1.Completely uninstall nodejs. Use the terminal commands described here: How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)
The commands you need to use are highlighted in gray. Use either one of the top two commands (they are the same, as the OP describes) and then run the bottom command he lists as well.
Install Nodejs through NVM as described in STEP 0 of this blog: http://nodesource.com/blog/installing-node-js-tutorial-using-nvm-on-mac-os-x-and-ubuntu/ Basically he isntructs you to run a few command in the terminals. Note that you do not need to install the LTS versions (I don-t even know what they do), unless you want to.
Verify that NVM was installed properly. Skip to STEP 3 of the above blog.
4.Refresh the terminal (open and close it) and then use the command "nvm use node" It will spit out the node version you are using.
Install browser-sync using the "npm install -g browser-sync" command
Verify that browser-sync installed using "browser-sync --version" command

Resources