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?

6
  • 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
    Commented Mar 25, 2022 at 10:10
  • 1
    Yes, I just found this issue. But now I'm more confused.. I thought electron was a module of node.. But node is also a module of electron?
    – wololoo
    Commented Mar 25, 2022 at 10:11
  • 1
    Electron uses node as a shared library. Check this out to get more details on it, electronjs.org/blog/electron-internals-using-node-as-a-library
    – DJ Hemath
    Commented Mar 25, 2022 at 10:15
  • Thank you! You can post this as an answer I guess :)
    – wololoo
    Commented Mar 25, 2022 at 10:20
  • Nope as per SO, just references to links can't be an actual answer. :-)
    – DJ Hemath
    Commented Mar 25, 2022 at 10:24

1 Answer 1

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

Comments

Enter at least 15 characters
Enter at least 15 characters

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.