0

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?

wololoo
  • 147
  • 1
  • 1
  • 9
  • 1
    I think electron is showing the version of the node embedded into it. It's not the version which is in your system. – DJ Hemath Mar 25 '22 at 10:10
  • 1
    Yes, I just found this [issue](https://github.com/electron/electron-quick-start/issues/232#issuecomment-433864297). But now I'm more confused.. I thought electron was a module of node.. But node is also a module of electron? – wololoo Mar 25 '22 at 10:11
  • 1
    Electron uses node as a shared library. Check this out to get more details on it, https://www.electronjs.org/blog/electron-internals-using-node-as-a-library – DJ Hemath Mar 25 '22 at 10:15
  • Thank you! You can post this as an answer I guess :) – wololoo Mar 25 '22 at 10:20
  • Nope as per SO, just references to links can't be an actual answer. :-) – DJ Hemath Mar 25 '22 at 10:24
  • You need to specify the version check out this click [HERE](https://stackoverflow.com/questions/64719704/electron-was-compiled-against-a-different-node-js-version) – Tanjin Alam Mar 25 '22 at 14:08

1 Answers1

1

@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).

midnight-coding
  • 2,857
  • 2
  • 17
  • 27