NG 构建在 Azure Pipelines 中失败,并出现 NPM 错误 134
Posted
技术标签:
【中文标题】NG 构建在 Azure Pipelines 中失败,并出现 NPM 错误 134【英文标题】:NG Build fails in Azure Pipelines with NPM error 134 【发布时间】:2019-09-05 20:24:49 【问题描述】:大约 50% 的托管构建失败并出现 npm 错误 134。我正在使用托管 vs2017 构建具有相同构建定义的相同提交。我正在使用 Angular CLI 构建一个 Angular 应用程序。 npm 任务调用“运行构建”,它在我的 package.json 中定义为“ng build --prod”。成功的构建和失败的构建都使用 npm 任务版本 1.1.49 和 npm 版本 6.8。这让我相信它与托管环境有关。托管的 vs2017 和 vs2019 代理几乎总是失败。而 windows 容器代理大约 50% 的时间会失败。
npm ERR! code ELIFECYCLE
npm ERR! errno 134
npm ERR! my-app@1.0.0 build: `ng build --prod`
npm ERR! Exit status 134
npm ERR!
npm ERR! Failed at the my-app@1.0.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:\npm\cache\_logs\TimeStampHere-debug.log
Found npm debug log, make sure the path matches with the one in npm's output: C:\npm\cache\_logs\TimeStampHere-debug.log
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\npm\\prefix\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'build' ]
2 info using npm@6.8.0
3 info using node@v10.15.2
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle my-app@1.0.0~prebuild: my-app@1.0.0
6 info lifecycle my-app@1.0.0~build: my-app@1.0.0
7 verbose lifecycle my-app@1.0.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle my-app@1.0.0~build: PATH: C:\npm\prefix\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;d:\a\1\s\ngmyapp\node_modules\.bin;C:\agents\2.149.2\externals\git\cmd;C:/hostedtoolcache/windows/Python/3.6.8/x64;C:/hostedtoolcache/windows/Python/3.6.8/x64/Scripts;C:\vcpkg;C:\cf-cli;C:\Program Files (x86)\NSIS\;C:\Program Files\Boost\1.69.0;C:\Users\VssAdministrator\.dotnet\tools;C:\Program Files\dotnet;C:\mysql-5.7.21-winx64\bin;C:\Program Files\Java\zulu-8-azure-jdk_8.36.0.1-8.0.202-win_x64\bin;C:\npm\prefix;C:\hostedtoolcache\windows\Ruby\2.5.0\x64\bin;C:\Go1.11.5\bin;C:\Program Files\Git\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin;C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\Scripts;C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64;C:\Program Files\Microsoft MPI\Bin\;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\ProgramData\Chocolatey\bin;C:\Program Files\Docker;C:\Program Files\PowerShell\6\;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\150\DTS\Binn\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Program Files\Microsoft Service Fabric\bin\Fabric\Fabric.Code;C:\Program Files\Microsoft SDKs\Service Fabric\Tools\ServiceFabricLocalClusterManager;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;c:\tools\php;C:\Program Files (x86)\Subversion\bin;C:\Program Files\nodejs\;C:\Program Files\CMake\bin;C:\Program Files\Mercurial;C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;C:\Program Files\OpenSSL\bin;C:\Users\VssAdministrator\AppData\Local\Microsoft\WindowsApps;
9 verbose lifecycle my-app@1.0.0~build: CWD: d:\a\1\s\ngmyapp
10 silly lifecycle my-app@1.0.0~build: Args: [ '/d /s /c', 'ng build --prod' ]
11 silly lifecycle my-app@1.0.0~build: Returned: code: 134 signal: null
12 info lifecycle my-app@1.0.0~build: Failed to exec build script
13 verbose stack Error: my-app@1.0.0 build: `ng build --prod`
13 verbose stack Exit status 134
13 verbose stack at EventEmitter.<anonymous> (C:\npm\prefix\node_modules\npm\node_modules\npm-lifecycle\index.js:301:16)
13 verbose stack at EventEmitter.emit (events.js:189:13)
13 verbose stack at ChildProcess.<anonymous> (C:\npm\prefix\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:189:13)
13 verbose stack at maybeClose (internal/child_process.js:970:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid my-app@1.0.0
15 verbose cwd d:\a\1\s\myapp
16 verbose Windows_NT 10.0.14393
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\npm\\prefix\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
18 verbose node v10.15.2
19 verbose npm v6.8.0
20 error code ELIFECYCLE
21 error errno 134
22 error my-app@1.0.0 build: `ng build --prod`
22 error Exit status 134
23 error Failed at the my-app@1.0.0 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 134, true ]
##[error]Error: Npm failed with return code: 134
##[section]Finishing: npm build
编辑:我已经在本地配置了构建代理,但我没有遇到问题。
【问题讨论】:
【参考方案1】:在我们的例子中,我们使用 Jenkins 构建服务器,但得到了同样的错误。我通过使用 progress=false 选项关闭构建进度的日志记录来解决它。
我们的 SPA 托管在 Visual Studio 项目中,因此该选项被添加到 *.csproj 文件中的构建命令中
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build -- --prod --progress=false" />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build:s-s-r -- --prod --progress=false" Condition=" '$(BuildServerSideRenderer)' == 'true' " />
【讨论】:
【参考方案2】:似乎问题的根源在于 node.js 内存不足。
https://github.com/angular/angular-cli/issues/13734
建议的解决方法是更改环境变量:
node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prod
【讨论】:
以上是关于NG 构建在 Azure Pipelines 中失败,并出现 NPM 错误 134的主要内容,如果未能解决你的问题,请参考以下文章
Blazor 范围内的 CSS 未在 Azure Pipelines 上构建
如何在 Azure Pipelines YAML 构建定义中接收修订
如何在 Azure DevOps Pipelines 上指定 Android SDK 构建工具版本
在 Azure Pipelines 上构建 .NET Core 3.0