Home > Enterprise >  Node version different when using NPM
Node version different when using NPM

Time:03-26

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?

CodePudding user response:

@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