Node version different when using NPM - node.js

I tried to find a duplicate question, there are similar ones but I still don't understand what's going on..
I just installed node and npm on Ubuntu 20.04 with
sudo apt install nodejs npm
And followed the Electron quick start tutorial, and added this line to the beginning of my main.js:
console.log("node version: " + process.versions["node"]);
When I run my app with npm start, I see (both on the console and on the app) node version 16.13.0, but when I run the app with node main, I see the version as 10.19.0, which is also what node -v shows.
I can probably "fix" this issue by updating node, but I would like to understand what is going on here.. Is NPM using a different node version or something?
Thanks
Edit
I tried this with an empty node app, just made npm init and set start: "node index.js" in package.json, this time both node index.js and npm start show the same version (10.19.0) so I'm guessing Electron is somehow reading a wrong node version?

#DJHemath is spot on. Electron has Node and Chromium as internal libraries. IE: Node is a module of Electron.
Therefore, the version you are seeing within your Electron application is the Node version that is bundled with Electron.
When Electron is updated, the versions of Node and Chromium are often updated as well. An overview of this can be seen on the Electron homepage "Releases" cards (latest, beta, alpha and nightly).
Additionally, for historical purposes, version updates of these two dependencies can be seen on the Stable Releases page.
Thus, in summary, changing your system's installed Node version will not affect the version of Node used within your Electron application(s).

Related

ReferenceError: primordials is not defined error when installing Semantic UI

I know that this question had been asked a lots of times (for instance - here), but either solutions didn't work or didn't fit my scenario.
The solution, offered in the link above, was:
Solution: Either upgrade to gulp 4 or downgrade to an earlier node.
So, here's what I have:
• Node: 12.18.1 (node -v)
• Gulp: CLI 2.3.0, Local version 4.0.2 (gulp -v)
I have created brand new react app:
npx create-react-app --template typescript react-app
Then I go to app folder (react-app) and execute the following command as on Semantic UI site:
npm install semantic-ui --save
However, I get the same error as in the question above. Here's the full output of this command:
If you don't want to roll back your version of Node, try using the actively maintained community fork of Semantic UI: Fomantic UI.
Run the command as you would with semantic-ui: npm i fomantic-ui
Fomantic is backwards-compatible with Semantic UI while resolving compatibility issues between Node 12 and Gulp 3 (which another thread references as being the root of the "primordials is not defined" issue).
Try going back to Node v10.
The thing is that Node v12 has a feature that is not compatible with Semantic-UI (Gulp 4.0.2), and that's why you get the error.
Please try upgrading your node.js to the latest version at https://nodejs.org/en/download/
and also run the following command npm install -g npm#7.0.9 or the latest version to update your npm.
After upgrading and updating Node and npm I installed semantic-ui without getting the primordial not defined error.

node printer.node is not a valid win32 application

I have developed a node API for my angular application, My node application uses node-printer package for printing pdf files generated by node, when i tried to run my application using nodemon i am getting an error
node printer.node is not a valid win32 application
The same application is working on the other machine without any error. both the machines are of X64 bit architecture.
also i have also tried to install node js 32 bit then too i am getting same error.
This worked for me, installing printer as such:
npm install printer --build-from-source
After so many attempts i have deleted node_modules folder from an application and fire an npm install command to add all modules again that resolves the problem.
Hi there let me go through what's happened on my site here in 2022.
So if you're going to use npm install printer for your Electron application, you're using a native module as deemed by electron.
Since Electron has a different application binary interface (ABI) from a given Node.js binary that you used to install your printer . Therefore, we need to rebuild the native module (in this case printer) for Electron.
For more detail check this out.
First, install electron-rebuild for your project. npm i electron-rebuild.
Second, install a native module using e.g. npm i printer
Third, after installed native module, execute ./node_modules/.bin/electron-rebuild to rebuild the native module.

Different versions of node on the same computer

I am working on two different angular projects on my computer.
If I run node -v on project A's root folder I get version 10.15.3 and if I run node -v on project B's root folder I get another version 12.1.
I don't understand why node is showing two different versions.
If I check the PATH of the node command it points to the same file /usr/bin/node.
thanks for replaying back. I am not using nvm. However I was checking another question here: link
node -v v10.15.3
nodejs -v v12.1.0
node comes from apt-get installed package (on Debian).
I was having issues when serving an ionic app, so I decided to remove npm version of node (v12.1.0):
npm remove -g node
Then I open another terminal and now node and nodejs are showing same version 10.15.3. For my testing purposes I need LTS version instead of latest in order to ensure less bug-prone code.

NodeJS server and React app can't use the same version of Node

Here is my problem and it might be super simple to fix, but I am new to the world of web technologies.
I have a react app that is running using node version 10.0.0. I am using npm n as my node version manager, and I am using n stable as my version selector.
When I try to run the NodeJS server that is supposed to accompany it, it fails when I try to run it with node version 10. I have to go back to version 4.9.1, so I can run the server without any problems.
Has anyone else faced this issue or know what it could be? If I go to a newer version of node I get a Bindings.js npm error. If I build my react app with 4.9.1, well that doesn't work at all.
To run both at the same time I have to switch to node version 4.9.1 and then run the nodeJS server, then change to version 10 and build the react app which to me is not how a production build should go.
Any thoughts?

Node JS 6.9 and angular CLI version compatibility

I have a restriction of using node JS version 6.9.1. I am getting many problems, while using angular cli quick start steps.
after ng serve, browser page will be white, no error in console.
npm start works, but if i change some style/file browser do not not refresh.
if i make any style change, webpack compiled successfully message comes but webserver fails to load page.
When I follow the quick start steps with latest nodejs it works like a charm. Can any one help me in telling, what are the versions (npm, angular-cli), I should use to run it ?
Like
Each Angular/Cli version has limited its compatibility of node versions below a specified release. If you have to use a specific version of node then your best bet would be to find a previous version of the Angular/Cli that will play nicely.
Here you can find all the versions and from there, pick one a little further back in the list and then do a search in google for "Angular/cli version x.x.x node compatibility" to see if there are any known issues.
Once you pick a version that looks good, run
npm install -g #angular/cli#<your version number>.
Once the install is complete run ng help and you'll get feedback right away if the version is still incompatible and you can try a different version.
Just make sure you get rid of the installs you aren't using with npm uninstall -g #angular/cli#<your version number>
for see if angular-cli is compatibility whit your node version installed you can see https://www.npmjs.com/package/#angular/cli/v/6.0.8?activeTab=versions, for example, I have installed node 6.11.2 and I have to use: npm install -g #angular/cli#6.0.0

Resources