使用电子生成器时“npm run dist”的问题

Posted

技术标签:

【中文标题】使用电子生成器时“npm run dist”的问题【英文标题】:problem with "npm run dist" when using electron-builder 【发布时间】:2020-02-16 20:27:07 【问题描述】:

我遇到了电子生成器的问题。

https://medium.com/how-to-electron/a-complete-guide-to-packaging-your-electron-app-1bdc717d739f

我已按照使用电子生成器打包电子应用程序的完整指南进行操作,但我不知道为什么会出现此错误。

任何想法将不胜感激。

这是我得到的示例错误日志。

1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Users\\ROG\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'dist' ]
2 info using npm@6.12.0
3 info using node@v10.16.0
4 verbose run-script [ 'predist', 'dist', 'postdist' ]
5 info lifecycle electron-quick-start@1.0.0~predist: electron-quick-start@1.0.0
6 info lifecycle electron-quick-start@1.0.0~dist: electron-quick-start@1.0.0
7 verbose lifecycle electron-quick-start@1.0.0~dist: unsafe-perm in lifecycle true
8 verbose lifecycle electron-quick-start@1.0.0~dist: PATH: C:\Users\ROG\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\xampp\htdocs\electron-quick-start\node_modules\.bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\Git\cmd;C:\xampp\php;C:\composer;C:\Program Files\nodejs\;C:\Program Files (x86)\Yarn\bin\;C:\Users\ROG\AppData\Local\Microsoft\WindowsApps;C:\Users\ROG\AppData\Roaming\Composer\vendor\bin;C:\Users\ROG\AppData\Roaming\npm;C:\Users\ROG\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\ROG\AppData\Local\Yarn\bin
9 verbose lifecycle electron-quick-start@1.0.0~dist: CWD: C:\xampp\htdocs\electron-quick-start
10 silly lifecycle electron-quick-start@1.0.0~dist: Args: [ '/d /s /c', 'build' ]
11 silly lifecycle electron-quick-start@1.0.0~dist: Returned: code: 1  signal: null
12 info lifecycle electron-quick-start@1.0.0~dist: Failed to exec dist script
13 verbose stack Error: electron-quick-start@1.0.0 dist: `build`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Users\ROG\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:198:13)
13 verbose stack     at ChildProcess.<anonymous> (C:\Users\ROG\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 electron-quick-start@1.0.0
15 verbose cwd C:\xampp\htdocs\electron-quick-start
16 verbose Windows_NT 10.0.17134
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\ROG\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "dist"
18 verbose node v10.16.0
19 verbose npm  v6.12.0
20 error code ELIFECYCLE
21 error errno 1
22 error electron-quick-start@1.0.0 dist: `build`
22 error Exit status 1
23 error Failed at the electron-quick-start@1.0.0 dist script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]```

here is my package.json

  "name": "electron-quick-start",
  "version": "1.0.0",
  "description": "A minimal Electron application",
  "main": "main.js",
  "scripts": 
    "postinstall": "install-app-deps",
    "start": "electron .",
    "pack": "build --dir",
    "dist": "build"
  ,
  "build": 
    "appID": "com.demo.quickstart",
    "win": 
      "target": ["nsis"],
      "icon": "build/icon.ico"
    
  ,
  "repository": "https://github.com/electron/electron-quick-start",
  "keywords": [
    "Electron",
    "quick",
    "start",
    "tutorial",
    "demo"
  ],
  "author": "GitHub",
  "license": "CC0-1.0",
  "devDependencies": 
    "electron": "^6.0.12",
    "electron-builder": "^21.2.0"
  


【问题讨论】:

【参考方案1】:

这个帖子已经相当不活跃了,所以我只是添加这个作为答案,也许它会有所帮助。

我注意到您的package.json 中没有directories 对象。

我不知道这是否重要,因为我自己无法解释这些错误。这是我在您的 package.json 与我的和我的预期作品之间看到的唯一区别。

看起来像这样。 output 相对于您的电子应用程序的根目录。

  "build": 
    "appID": "com.demo.quickstart",
    "directories": 
      "output": "build"
    ,
    "win": 
      "target": ["nsis"],
      "icon": "build/icon.ico"
    
  

请告诉我你的进展如何 希望对你有帮助

【讨论】:

以上是关于使用电子生成器时“npm run dist”的问题的主要内容,如果未能解决你的问题,请参考以下文章

使用电子生成器构建电子时如何排除文件?

使用电子生成器构建时,电子应用程序显示空白屏幕

放入文件服务器时,电子打包器和电子生成器错误使用电子 vue 构建

使用电子生成器设置电子图标

设计在更新时不确认电子邮件

在 Angular 5 中使用电子生成器构建电子应用程序