Search code examples
node.jselectronelectron-packagernode-sqlite3electron-rebuild

Electron Packager Script Error using Electron Rebuilt


I am working with an Electron app where I used sqlite3. Because of I am using sqlite3, I rebuilt the project using "electron-rebuild" following the command:

electron-rebuild -f -w sqlite3 

Then It works successfully.

After finalizing my project, I need to make a package using "Electron-Packager". That's why I wrote a script ('build.js') with the help of the internet. The script is below:

const packager = require('electron-packager');
const rebuild = require('electron-rebuild');

packager({
    buildPath: __dirname,
    electronVersion: '7.1.2',
    dir: '../output',
    overwrite: true,
    asar: true,
    platform: 'win32',
    arch: 'ia32',
    icon: '/src/img/icon.ico',
    prune: true,
    out: 'project-name',
    executableName: 'project-name',
    afterCopy: [(buildPath, electronVersion, platform, arch, callback) => {
        rebuild.rebuild({ buildPath, electronVersion, arch })
            .then(() => callback())
            .catch((error) => callback(error));
    }],
})

After I run the script, I got an error and that is:


(node:7712) UnhandledPromiseRejectionWarning: Error: Unable to find all properties in parent package.json files. Missing props: ["productName","name"], "version", "author"
    at C:\[[project-location]]\node_modules\get-package-info\lib\index.js:23:17
    at tryCatcher (C:\[[project-location]]\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (C:\[[project-location]]\node_modules\bluebird\js\release\promise.js:547:31)
    at Promise._settlePromise (C:\[[project-location]]\node_modules\bluebird\js\release\promise.js:604:18)
    at Promise._settlePromise0 (C:\[[project-location]]\node_modules\bluebird\js\release\promise.js:649:10)
    at Promise._settlePromises (C:\[[project-location]]\node_modules\bluebird\js\release\promise.js:729:18)
    at _drainQueueStep (C:\[[project-location]]\node_modules\bluebird\js\release\async.js:93:12)
    at _drainQueue (C:\[[project-location]]\node_modules\bluebird\js\release\async.js:86:9)
    at Async._drainQueues (C:\[[project-location]]\node_modules\bluebird\js\release\async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (C:\[[project-location]]\node_modules\bluebird\js\release\async.js:15:14)
    at processImmediate (internal/timers.js:439:21)
(node:7712) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:7712) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

The package.json I am using is:

{
  "name": "project-name",
  "version": "1.0.0",
  "description": "",
  "main": "main.js",
  "scripts": {
    "start": "electron .",
    "rebuild": "electron-rebuild -f -w sqlite3 ",
    "package": "node build.js"
  },
  "productName": "project-name",
  "author": "Takiuddin Ahmed",
  "license": "MIT",
  "devDependencies": {
    "electron": "^7.1.2",
    "electron-packager": "^14.2.0",
    "electron-rebuild": "^1.9.0"
  },
  "dependencies": {
    "sqlite3": "^4.1.1"
  }
}

Solution

  • I solve the problem by rewriting the 'build.js'.

    I got API Documentation of electron packager and there I found that some options I need the specify in my build script. Among these options win32metadata.companyName, name, and buildVersion are mandatory, but by default, the values should set from 'package.json'. The 'win32metadata.companyName' defaults to 'author' name, 'name' defaults to 'productName' and 'buildVersion' defaults to 'version' from package.json. But anyhow the program can not get these options from 'package.json'. So, I just specify these options in 'build.js'. and it works. My final 'build.js' script is:

    
    const packager = require('electron-packager');
    const rebuild = require('electron-rebuild');
    
    packager({
        name: "project-name",
        buildPath: __dirname,
        electronVersion: '7.1.2',
        version: '1.0.1',
        buildVersion: '1.0.1',
        dir: '../output',
        overwrite: true,
        asar: true,
        platform: 'win32',
        arch: 'ia32',
        icon: '/src/img/icon.ico',
        prune: true,
        appVersion: "1.0.1",
        win32metadata: {
            CompanyName: "Takiuddin Ahmed"
        },
        afterCopy: [(buildPath, electronVersion, platform, arch, callback) => {
            rebuild({ buildPath, electronVersion, arch })
                .then(() => callback())
                .catch((error) => callback(error));
        }],
    });