使用 Github Actions 发布 React+dotnet 核心应用程序抛出错误 MSB3073: The command "npm run build" exited w

Posted

技术标签:

【中文标题】使用 Github Actions 发布 React+dotnet 核心应用程序抛出错误 MSB3073: The command "npm run build" exited with code 1【英文标题】:Publishing React+dotnet core application using Github Actions throwing error MSB3073: The command "npm run build" exited with code 1 【发布时间】:2021-05-15 10:00:09 【问题描述】:

我在使用 Github Actions 发布 React+dotnet 核心应用程序时遇到以下错误。我在 Windows Server 2016 上使用 GitHub 自托管运行器。

npm ERR! code ELIFECYCLE
  npm ERR! errno 1
  npm ERR! ptrx_backoffice@0.1.0 build: `react-scripts build`
  npm ERR! Exit status 1
  npm ERR! 
  npm ERR! Failed at the ptrx_backoffice@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\Administrator\AppData\Roaming\npm-cache\_logs\2021-02-11T15_54_47_880Z-debug.log
D:\aayush\ptrx_backoffice\ptrx_backoffice\PTRX_BackOffice.csproj(49,5): error MSB3073: The command "npm run build" exited with code 1.
Error: Process completed with exit code 1.

日志文件2021-02-11T15_54_47_880Z-debug.log 输出如下。我曾尝试使用 npm 删除节点模块,清理缓存,但这似乎不是 NPM 的问题,因为它在日志中清楚地表明这与 NPM 无关。请让我知道是否有人可以提供帮助。

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   'build'
1 verbose cli ]
2 info using npm@6.13.4
3 info using node@v12.16.0
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle ptrx_backoffice@0.1.0~prebuild: ptrx_backoffice@0.1.0
6 info lifecycle ptrx_backoffice@0.1.0~build: ptrx_backoffice@0.1.0
7 verbose lifecycle ptrx_backoffice@0.1.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle ptrx_backoffice@0.1.0~build: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;D:\aayush\ptrx_backoffice\ptrx_backoffice\ClientApp\node_modules\.bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\php\v7.1;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\;C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files\dotnet\;C:\Program Files (x86)\dotnet\;C:\Users\Administrator\AppData\Roaming\npm;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;C:\Apache24\bin;C:\Users\Administrator\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\PuTTY\;C:\python\Scripts\;C:\python\;C:\Program Files\Scripts\;C:\Program Files\;C:\Users\Administrator\AppData\Roaming\npm;C:\Apache24\bin;C:\Program Files\JetBrains\PyCharm Community Edition 2020.1\bin;;C:\Users\Administrator\.dotnet\tools
9 verbose lifecycle ptrx_backoffice@0.1.0~build: CWD: D:\aayush\ptrx_backoffice\ptrx_backoffice\ClientApp
10 silly lifecycle ptrx_backoffice@0.1.0~build: Args: [ '/d /s /c', 'react-scripts build' ]
11 silly lifecycle ptrx_backoffice@0.1.0~build: Returned: code: 1  signal: null
12 info lifecycle ptrx_backoffice@0.1.0~build: Failed to exec build script
13 verbose stack Error: ptrx_backoffice@0.1.0 build: `react-scripts build`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:321:20)
13 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:321:20)
13 verbose stack     at maybeClose (internal/child_process.js:1021:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
14 verbose pkgid ptrx_backoffice@0.1.0
15 verbose cwd D:\aayush\ptrx_backoffice\ptrx_backoffice\ClientApp
16 verbose Windows_NT 6.3.9600
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
18 verbose node v12.16.0
19 verbose npm  v6.13.4
20 error code ELIFECYCLE
21 error errno 1
22 error ptrx_backoffice@0.1.0 build: `react-scripts build`
22 error Exit status 1
23 error Failed at the ptrx_backoffice@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 ]

【问题讨论】:

【参考方案1】:

根据这个链接:

https://social.msdn.microsoft.com/Forums/vstudio/en-US/f70c2425-14de-49cf-b228-d29548c9ef87/getting-error-msb3073?forum=msbuild

您可能在某处设置了错误的路径,只是引用文章:

一般来说,错误MSB3073一般是由于命令行路径不正确造成的。

现在,在您的 PATH 中,特别是这个值:

D:\aayush\ptrx_backoffice\ptrx_backoffice\ClientApp\node_modules\.bin;

但是,这似乎是问题所在,你调用这个命令:

C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"

看起来您正在尝试执行一个不存在的二进制文件。

我的感觉是您在生产环境中使用了开发环境变量。

【讨论】:

以上是关于使用 Github Actions 发布 React+dotnet 核心应用程序抛出错误 MSB3073: The command "npm run build" exited w的主要内容,如果未能解决你的问题,请参考以下文章

使用 GitHub Actions 创建标签而不是发布

如何使用 Github Actions 进行 SFTP?

如何使用 Github Actions 发布对 Docker 镜像的更改

MapDispatchToProps 导致父组件中的 Typescript 错误,期望 Actions 作为 props 传递

如何在 GitHub Actions 中使用最新发布标签?

是否可以在 GitHub Actions 中的 Actions 之间保留 WORKDIR?