首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Electron重建的电子打包程序脚本错误

使用Electron重建的电子打包程序脚本错误
EN

Stack Overflow用户
提问于 2020-02-08 06:56:12
回答 1查看 471关注 0票数 0

我正在使用一个电子应用程序,其中我使用了sqlite3。因为我使用的是sqlite3,所以我按照下面的命令使用“rebuilt rebuild”重新构建了项目:

代码语言:javascript
复制
electron-rebuild -f -w sqlite3 

那么它就成功地工作了。

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

代码语言:javascript
复制
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));
    }],
})

在我运行脚本之后,我得到了一个错误,即:

代码语言:javascript
复制
(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是:

代码语言:javascript
复制
{
  "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"
  }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-08 22:12:12

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

我得到了电子打包器的API Documentation,在那里我发现了一些我需要在构建脚本中指定的选项。在这些选项中,win32metadata.companyName、name和buildVersion是必需的,但默认情况下,这些值应该从'package.json‘开始设置。'win32metadata.companyName‘默认为'author’name,'name‘默认为'productName’,'buildVersion‘默认为package.json中的'version’。但不管怎样,程序不能从'package.json‘获得这些选项。所以,我只是在'build.js‘中指定了这些选项。而且它是有效的。我的最后一个'build.js‘脚本是:

代码语言:javascript
复制
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));
    }],
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60122197

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档