【问题标题】:Electron Packager Script Error using Electron Rebuilt使用 Electron Rebuilt 的 Electron Packager 脚本错误
【发布时间】:2020-02-08 22:12:11
【问题描述】:

我正在使用一个使用 sqlite3 的 Electron 应用程序。因为我使用的是 sqlite3,所以我按照以下命令使用“electron-rebuild”重建了项目:

electron-rebuild -f -w sqlite3 

然后它就成功了。

完成我的项目后,我需要使用“Electron-Packager”制作一个包。这就是为什么我在互联网的帮助下编写了一个脚本('build.js')。脚本如下:

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));
    }],
})

在我运行脚本后,我得到了一个错误,那就是:


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

我使用的 package.json 是:

{
  "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"
  }
}

【问题讨论】:

    标签: node.js electron electron-packager node-sqlite3 electron-rebuild


    【解决方案1】:

    我通过重写“build.js”解决了这个问题。

    我得到了电子打包程序的API Documentation,在那里我发现我需要在构建脚本中指定一些选项。在这些选项中,win32metadata.companyName、name 和 buildVersion 是必需的,但默认情况下,值应从“package.json”设置。 “win32metadata.companyName”默认为“作者”名称,“名称”默认为“产品名称”,“buildVersion”默认为 package.json 中的“版本”。但无论如何,该程序无法从“package.json”中获取这些选项。所以,我只是在“build.js”中指定这些选项。它有效。我最终的“build.js”脚本是:

    
    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));
        }],
    });
    

    【讨论】:

      猜你喜欢
      • 2017-09-28
      • 2017-01-29
      • 2020-01-18
      • 1970-01-01
      • 2021-03-29
      • 2018-10-03
      • 2020-03-24
      • 1970-01-01
      • 2021-09-02
      相关资源
      最近更新 更多