electron: app.getVersion returns electron binary version instead of package.json field

  • Electron version: 1.3.3
  • Operating system: OSX El Capitan (10.11.5)

Just calling app.getVersion() and i’m getting electron’s binary version instead of version I set in my package.json (2-package.json structure).

Of course, my app/package.json has the version field:

{
  "name": "Name",
  "version": "0.0.1",
  "productName": "ProdName",
  "description": "Desc Desc",
  "homepage": "https://github.com/oxcarga/ProdName",
  "license": ""
}

In Main process:

const {app} = require('electron')
app.on('ready', function () {
    console.log(app.getVersion())
})

Or, in Renderer process:

const {app} = require('electron').remote
console.log(app.getVersion(), app.getName())

In both places I get “1.3.3” (which is the version of electron I’m running)

According to docs:

app.getVersion() Returns the version of the loaded application. If no version is found in the application’s package.json file, the version of the current bundle or executable is returned.

Am I missing something?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 8
  • Comments: 15 (1 by maintainers)

Most upvoted comments

In development the version returned by app.getVersion() depends on how you launched your app. If you launched it with electron path/to/app/package_dir the version will match the one in your package.json, however, if you launched your app with electron path/to/main.js then you’ll get the Electron version. This is because in the latter case Electron will actually read the package.json of the default app, which doesn’t specify a version, so it will default to the Electron version. Once you package your app the version will always be read from your package.json.

you can also use process.env.npm_package_version

app.app.getVersion(); works for me, might be an error in the docs, or a problem with using the 2-package.json structure

This is normal behaviour, you can check whether you’re in dev mode or in production, and, if you are, you can read from your native package.json file.

    let { currentVersion } = '';

    if (process.env.NODE_ENV === 'development') {
      currentVersion = require('../../../package.json').version;
    } else {
      currentVersion = require('electron').remote.app.getVersion();
    }

Just require app via remote

const {app} = require('electron').remote

I had the same issue if i was using

electron index.js

This was probably bypassing package.json and thus was showing the electron version

I then changed start script in package.json to

electron .

and now it shows version from package.json

I am using Electron + Typescript, so the start script in my package.json is:

"start": "npm run build && electron ./dist/main.js"

When doing app.getVersion with Electron 9, I get electron’s version.

When using Electron 8.3.0, I get my package.json’ version, which is what I expect.

Also seeing this happen. Is there a reason the issue was closed? It doesn’t seem to be resolved at all. I’m using electron-webpack, so the workarounds in this thread don’t work for me