npm run build 给出 npm ERR!代码生命周期

Posted

技术标签:

【中文标题】npm run build 给出 npm ERR!代码生命周期【英文标题】:npm run build gives out npm ERR! code ELIFECYCLE 【发布时间】:2017-12-27 11:20:33 【问题描述】:

我是 Node.js 和 Electron 的新手,想运行 npm run build。不幸的是,这只给了我错误代码 ELIFECYCLE。

这是我的 package.json


    "name": "firstelectronproject",
    "version": "0.1.0",
    "description": "My first Electron project",
    "main": "main.js",
    "scripts": 
        "start": "electron index.js",
        "package": "",
        "build": "electron-packager . FEP"
    ,
    "author": "F9lke <florian.thomasgoetzrath.de>",
    "license": "MIT",
    "dependencies": 
        "electron": "^1.6.11"
    ,
    "devDependencies": 
        "asar": "^0.13.0",
        "electron-packager": "^8.7.2"
    

这是我的命令提示符的日志:

 D:\Eigene Dateien\Desktop\Coding\Desktop Apps\FEP>npm run build

> firstelectronproject@0.1.0 build D:\Eigene Dateien\Desktop\Coding\Desktop Apps\FEP
> electron-packager . FEP

Packaging app for platform win32 x64 using electron v1.6.11
Command failed: npm prune --production
npm WARN invalid config loglevel="notice"
npm WARN firstelectronproject@0.1.0 No repository field.

npm ERR! May not delete: C:\Users\User\AppData\Local\Temp\electron-packager\win32-x64\FEP-win32-x64\resources\app\node_modules\.bin

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\User\AppData\Roaming\npm-cache\_logs\2017-07-21T11_38_37_230Z-debug.log

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! firstelectronproject@0.1.0 build: `electron-packager . FEP`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the firstelectronproject@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\User\AppData\Roaming\npm-cache\_logs\2017-07-21T11_38_37_293Z-debug.log  

这里是日志输出:

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Users\\User\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'build' ]
2 info using npm@5.3.0
3 info using node@v6.11.1
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle firstelectronproject@0.1.0~prebuild: firstelectronproject@0.1.0
6 info lifecycle firstelectronproject@0.1.0~build: firstelectronproject@0.1.0
7 verbose lifecycle firstelectronproject@0.1.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle firstelectronproject@0.1.0~build: PATH: C:\Users\User\AppData\Roaming\npm\node_modules\npm\bin\node-gyp-bin;D:\Eigene Dateien\Desktop\Coding\Desktop Apps\FEP\node_modules\.bin;C:\Program Files (x86)\Razer Chroma SDK\bin;C:\Program Files\Razer Chroma SDK\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)\NVIDIA Corporation\PhysX\Common;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:\Windows\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps;C:\Program Files (x86)\Brackets\command;C:\Program Files\nodejs\;C:\Users\User\AppData\Local\Microsoft\WindowsApps;C:\Users\User\AppData\Local\atom\bin;C:\Users\User\AppData\Roaming\npm
9 verbose lifecycle firstelectronproject@0.1.0~build: CWD: D:\Eigene Dateien\Desktop\Coding\Desktop Apps\FEP
10 silly lifecycle firstelectronproject@0.1.0~build: Args: [ '/d /s /c', 'electron-packager . FEP' ]
11 silly lifecycle firstelectronproject@0.1.0~build: Returned: code: 1  signal: null
12 info lifecycle firstelectronproject@0.1.0~build: Failed to exec build script
13 verbose stack Error: firstelectronproject@0.1.0 build: `electron-packager . FEP`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Users\User\AppData\Roaming\npm\node_modules\npm\lib\utils\lifecycle.js:289:16)
13 verbose stack     at emitTwo (events.js:106:13)
13 verbose stack     at EventEmitter.emit (events.js:191:7)
13 verbose stack     at ChildProcess.<anonymous> (C:\Users\User\AppData\Roaming\npm\node_modules\npm\lib\utils\spawn.js:40:14)
13 verbose stack     at emitTwo (events.js:106:13)
13 verbose stack     at ChildProcess.emit (events.js:191:7)
13 verbose stack     at maybeClose (internal/child_process.js:891:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
14 verbose pkgid firstelectronproject@0.1.0
15 verbose cwd D:\Eigene Dateien\Desktop\Coding\Desktop Apps\FEP
16 verbose Windows_NT 10.0.15063
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\User\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
18 verbose node v6.11.1
19 verbose npm  v5.3.0
20 error code ELIFECYCLE
21 error errno 1
22 error firstelectronproject@0.1.0 build: `electron-packager . FEP`
22 error Exit status 1
23 error Failed at the firstelectronproject@0.1.0 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

【问题讨论】:

你的项目有链接吗?尝试在我的机器上重现,如果我能得到完整的项目,那就太好了。 请尝试 .\node_modules\.bin\eslint (路径分隔符在 Windows 上为 \)或 yarn add eslint-cli 【参考方案1】:

这似乎与electron-packager 中的一个错误有关。作为一种解决方法,您可以将electron-packager 降级为例如^7.7.0。另外,您需要稍微更新build 命令,见下文(注意,仅显示相关部分):


  "scripts":                                                  
    "build": "electron-packager ./ --platform=linux --arch=x64"
  ,                                                           
  "dependencies":                                             
    "electron": "^1.6.11"                                      
  ,                                                           
  "devDependencies": 
    "electron-packager": "^7.7.0"                              
                                                              
                                                              

请注意,您可以使用--all 为所有平台构建。

【讨论】:

所以所有平台都是“--platform=--all”?非常感谢! 不,我认为只是--all【参考方案2】:

在服务器上更新 npm 对我有用。

【讨论】:

【参考方案3】:

我通过安装阵列unique 解决了这个问题,它开始工作了:

npm install --save array-unique

【讨论】:

【参考方案4】:

我在使用电子打包器时遇到了类似的问题。刚刚将 ./ --all 添加到 pack 指令的末尾。最终结果如下:

"pack": "electron-packager ./ --all"

【讨论】:

以上是关于npm run build 给出 npm ERR!代码生命周期的主要内容,如果未能解决你的问题,请参考以下文章

laravel npm run production 编译成功,但是 npm ERR!代码生命周期

vue中Npm run build 根据环境传递参数方法来打包不同域名

(在本地运行项目)npm报错:npm ERR! missing script: start npm ERR! A complete log of this run can be found in:

Vue报错:npm run start npm ERR! missing script: start

npm ERR! missing script: build

关于vue的npm run dev和npm run build