错误:使用电子包装机进行电子包装

时间:2019-07-25 01:11:37

标签: node.js npm electron electron-packager

我正在尝试使用electronic-packager包装我的ember-electron应用程序。

这是针对运行Ember-electron,ember-cli:3.11.0,node:10.16.0的Windows electronic app。过去,它运行良好,但是在删除“ electron-out”,“ dist”和“ release-builds”文件夹后,出现了错误。

{
    "name": "messenger",
    "productName": "Messenger",
    "version": "0.0.77",
    "main": "./ember-electron/main.js",
    "private": true,
    "scripts": {
        "build": "ember build",
        "package-win": "electron-packager . --project-path=electron-out/project --overwrite --platform=win32 --arch=x64 --icon=assets/messenger.ico --no-prune ---app-version=\"1.0.0.77\" --executable-name=\"Messenger\" --out=release-builds",

        "lint:hbs": "ember-template-lint .",
        "lint:js": "eslint .",
        "start": "ember serve",
        "test": "ember test"
    },
    "devDependencies": {
    "electron": "^5.0.8",
    "electron-builder": "^20.40.2",
    "electron-forge": "^5.2.4",
    "electron-packager": "^14.0.2",
    "electron-prebuilt-compile": "3.0.2",
    "electron-winstaller": "^2.7.0",
    ....
}

这是我得到的错误日志:

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Users\\userName\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'package-win' ]
2 info using npm@6.10.1
3 info using node@v10.16.0
4 verbose run-script [ 'prepackage-win', 'package-win', 'postpackage-win']
5 info lifecycle messenger@0.0.77~prepackage-win: messenger@0.0.77
6 info lifecycle messenger@0.0.77~package-win: messenger@0.0.77
7 verbose lifecycle messenger@0.0.77~package-win: unsafe-perm in lifecycle true
8 verbose lifecycle messenger@0.0.77~package-win: PATH:C:\Users\userName\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\messenger\New\client\node_modules\.bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\dotnet\;C:\Program Files (x86)\Microsoft Emulator Manager\1.0\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Python27;C:\Python27\Scripts;C:\Program Files (x86)\Yarn\bin\;C:\Program Files\OpenSSL-Win64\bin;C:\Program Files\MySQL\MySQL Utilities 1.6\;C:\PHP\;C:\Apache24\bin;C:\Program Files\PuTTY\;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\TortoiseSVN\bin;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\cygwin64\bin;C:\Python27\Scripts\;C:\Python27\;C:\Users\userName\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Bandizip\;C:\Program Files\Sublime Text 3;C:\Users\userName\AppData\Local\Yarn\bin;C:\Program Files (x86)\Yarn;C:\Program Files\OpenSSL-Win64\bin;C:\PHP\;C:\Apache24\bin;C:\Users\userName\AppData\Roaming\npm;C:\cygwin64\bin;
9 verbose lifecycle messenger@0.0.77~package-win: CWD: C:\messenger\New\client
10 silly lifecycle messenger@0.0.77~package-win: Args: [ '/d /s /c', 'electron-packager . ' ]
11 silly lifecycle messenger@0.0.77~package-win: Returned: code: 1  signal: null
12 info lifecycle messenger@0.0.77~package-win: Failed to exec package-win script
13 verbose stack Error: messenger@0.0.77 package-win: `electron-packager . --project-path=electron-out/project --overwrite --platform=win32 --arch=x64 --icon=assets/messenger.ico --no-prune ---app-version=\"1.0.0.77\" --executable-name=\"Messenger\" --out=release-builds",`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous (C:\Users\userName\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\index.js:301:16)
13 verbose stack     at EventEmitter.emit (events.js:198:13)
13 verbose stack     at ChildProcess.<anonymous> (C:\Users\userName\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:198:13)
13 verbose stack     at maybeClose (internal/child_process.js:982:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid messenger@0.0.77
15 verbose cwd C:\messenger\New\client
16 verbose Windows_NT 10.0.17763
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\userName\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "package-win"
18 verbose node v10.16.0
19 verbose npm  v6.10.1
20 error code ELIFECYCLE
21 error errno 1
22 error messenger@0.0.77 package-win: `electron-packager . --project-path=electron-out/project --overwrite --platform=win32 --arch=x64 --icon=assets/messenger.ico --no-prune ---app-version=\"1.0.0.77\" --executable-name=\"Messenger\" --out=release-builds",`
22 error Exit status 1
23 error Failed at the messenger@0.0.77 package-win script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

1 个答案:

答案 0 :(得分:0)

我建议您改用 electron-builder 。我已经写了Medium article对此进行了详细记录,您可以在GitHub上找到我的complete project

但是除此之外,这里有一个快速概述。首先添加electron-builder

npm install electron-builder --save-dev

要使electron-builder工作,您需要指出构建中必须包含哪些文件。您可以通过package.json中的构建密钥来实现。假设您在名为app/的文件夹中编译文件。然后,您只需要添加它们在node_modules文件夹中找到的依赖项(请记住,一个独立的应用程序必须包含所有内容)。因此,请在您的package.json中添加“构建”键:

"build": {
  "appId": "com.electron.build.example",
  "files": [
    "app/**/*",
    "node_modules/**/*",
    "package.json"
  ],
  "publish": null
}

添加调用(发布)构建的脚本:

"scripts": {
  "postinstall": "install-app-deps",
  "start": "gulp start",
  "release": "gulp release"
},

我使用了gulp,但是您可以使用任何您想使用的东西(甚至可以直接从npm调用电子制造器)。由你决定。就我而言,我只需要在gulp文件中包含该任务即可。请注意,我使用exec而不是spawn以便可以在Windows计算机上交叉编译。

const exec = require('child_process').exec;
gulp.task('release', ['build'], () => {
    return exec(        
        __dirname+'/node_modules/.bin/electron-builder .'
    ).on('close', () => process.exit());
});