我正在使用create-react-app开发一个Electron应用程序,但是在构建该应用程序时遇到了麻烦。我只想将其输出到Windows。
这是我的package.json。
{
"name": "lierno-frontend",
"version": "0.1.0",
"private": true,
"main": "public/electron.js",
"homepage": "./",
"author": {
"name": "KuluGary",
"email": "kululu.gay@gmail.com",
"url": "https://lierno.netlify.app"
},
"build": {
"appId": "com.lierno.app",
"productName": "Lierno",
"copyright": "Copyright © 2019 ${author}",
"win": {
"target": [
"nsis",
"msi"
]
},
"files": [
"build/**/*",
"node_modules/**/*"
],
"directories": {
"buildResources": "resources",
"output": "release"
}
},
"dependencies": {
"@material-ui/core": "^4.9.10",
"@material-ui/icons": "^4.9.1",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
"electron-is-dev": "^1.2.0",
"jwt-decode": "^2.2.0",
"leaflet": "^1.6.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-leaflet": "^2.6.3",
"react-modal-image": "^2.5.0",
"react-redux": "^7.2.0",
"react-router-dom": "^5.1.2",
"react-scripts": "3.4.1",
"redux": "^4.0.5"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"electron-dev": "concurrently \"BROWSER=none npm start\" \"wait-on http://localhost:3000 && electron .\"",
"postinstall": "electron-builder install-app-deps",
"preelectron-pack": "npm run build",
"electron-pack": "electron-builder -w"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"concurrently": "^5.2.0",
"electron": "^8.2.5",
"electron-builder": "^22.6.0",
"typescript": "^3.8.3",
"wait-on": "^4.0.2"
}
}
这是我的public / electron.js
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const path = require('path');
const isDev = require('electron-is-dev');
let mainWindow;
function createWindow() {
mainWindow = new BrowserWindow({width: 900, height: 680});
mainWindow.loadURL(isDev ? 'http://localhost:3000' : `file://${path.join(__dirname, '../build/index.html')}`);
if (isDev) {
// Open the DevTools.
//BrowserWindow.addDevToolsExtension('<location to your react chrome extension>');
mainWindow.webContents.openDevTools();
}
mainWindow.on('closed', () => mainWindow = null);
}
app.on('ready', createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (mainWindow === null) {
createWindow();
}
});
这是我的日志:
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'electron-pack'
1 verbose cli ]
2 info using npm@6.13.4
3 info using node@v12.14.1
4 verbose run-script [ 'preelectron-pack', 'electron-pack', 'postelectron-pack' ]
5 info lifecycle lierno-frontend@0.1.0~preelectron-pack: lierno-frontend@0.1.0
6 verbose lifecycle lierno-frontend@0.1.0~preelectron-pack: unsafe-perm in lifecycle true
7 verbose lifecycle lierno-frontend@0.1.0~preelectron-pack: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\garyc\Programación\eg-lierno-app\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\nodejs\;C:\Program Files\Git\cmd;C:\Users\garyc\AppData\Local\Microsoft\WindowsApps;C:\Users\garyc\AppData\Roaming\npm;C:\Users\garyc\AppData\Local\Programs\Microsoft VS Code\bin;C:\mongodb\bin;C:\Program Files\heroku\bin
8 verbose lifecycle lierno-frontend@0.1.0~preelectron-pack: CWD: C:\Users\garyc\Programación\eg-lierno-app\client
9 silly lifecycle lierno-frontend@0.1.0~preelectron-pack: Args: [ '/d /s /c', 'npm run build' ]
10 silly lifecycle lierno-frontend@0.1.0~preelectron-pack: Returned: code: 0 signal: null
11 info lifecycle lierno-frontend@0.1.0~electron-pack: lierno-frontend@0.1.0
12 verbose lifecycle lierno-frontend@0.1.0~electron-pack: unsafe-perm in lifecycle true
13 verbose lifecycle lierno-frontend@0.1.0~electron-pack: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\garyc\Programación\eg-lierno-app\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\nodejs\;C:\Program Files\Git\cmd;C:\Users\garyc\AppData\Local\Microsoft\WindowsApps;C:\Users\garyc\AppData\Roaming\npm;C:\Users\garyc\AppData\Local\Programs\Microsoft VS Code\bin;C:\mongodb\bin;C:\Program Files\heroku\bin
14 verbose lifecycle lierno-frontend@0.1.0~electron-pack: CWD: C:\Users\garyc\Programación\eg-lierno-app\client
15 silly lifecycle lierno-frontend@0.1.0~electron-pack: Args: [ '/d /s /c', 'electron-builder -w' ]
16 silly lifecycle lierno-frontend@0.1.0~electron-pack: Returned: code: 1 signal: null
17 info lifecycle lierno-frontend@0.1.0~electron-pack: Failed to exec electron-pack script
18 verbose stack Error: lierno-frontend@0.1.0 electron-pack: `electron-builder -w`
18 verbose stack Exit status 1
18 verbose stack at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
18 verbose stack at EventEmitter.emit (events.js:223:5)
18 verbose stack at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
18 verbose stack at ChildProcess.emit (events.js:223:5)
18 verbose stack at maybeClose (internal/child_process.js:1021:16)
18 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
19 verbose pkgid lierno-frontend@0.1.0
20 verbose cwd C:\Users\garyc\Programación\eg-lierno-app\client
21 verbose Windows_NT 10.0.18363
22 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "electron-pack"
23 verbose node v12.14.1
24 verbose npm v6.13.4
25 error code ELIFECYCLE
26 error errno 1
27 error lierno-frontend@0.1.0 electron-pack: `electron-builder -w`
27 error Exit status 1
28 error Failed at the lierno-frontend@0.1.0 electron-pack script.
28 error This is probably not a problem with npm. There is likely additional logging output above.
29 verbose exit [ 1, true ]
在dev中运行它时效果很好,但是如您所见,在编译时失败,并且没有.exe保存在发行文件夹中。有谁知道它在哪里失败以及解决方案?