TFS:构建 React 项目失败

Posted

技术标签:

【中文标题】TFS:构建 React 项目失败【英文标题】:TFS: Building a React project fails 【发布时间】:2021-11-25 15:04:46 【问题描述】:

我有一个具有 TFS 构建定义的项目,它工作正常。

我有一个 TFS 构建的第二个项目(从有效的那个复制而来)但是当它执行时 npm run build 它失败了。

******************************************************************************
Starting: npm run build
******************************************************************************
==============================================================================
Task         : npm
Description  : Install and publish npm packages, or run an npm command. Supports npmjs.com and authenticated registries like Package Management.
Version      : 1.0.5
Author       : Microsoft Corporation
Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613746)
==============================================================================
C:\Windows\system32\cmd.exe /D /S /C ""C:\Program Files\nodejs\npm.cmd" config list"
; cli configs
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/5.6.0 node/v8.9.4 win32 x64"
; environment configs
userconfig = "D:\\agent\\_work\\11\\npm\\11028.npmrc"
; builtin config undefined
prefix = "C:\\Windows\\ServiceProfiles\\NetworkService\\AppData\\Roaming\\npm"
; node bin location = C:\Program Files\nodejs\node.exe
; cwd = D:\agent\_work\11\s
; HOME = C:\Windows\ServiceProfiles\NetworkService
; "npm config ls -l" to show all defaults.
C:\Windows\system32\cmd.exe /D /S /C ""C:\Program Files\nodejs\npm.cmd" run build"
> projectname@0.1.0 build D:\agent\_work\11\s
> react-scripts build
D:\agent\_work\11\s\node_modules\fs-extra\lib\mkdirs\make-dir.js:85
       catch 
              ^
SyntaxError: Unexpected token 
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:607:28)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Module.require (module.js:587:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (D:\agent\_work\11\s\node_modules\fs-extra\lib\mkdirs\index.js:3:44)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! projectname@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the projectname@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:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\npm-cache\_logs\2021-10-05T10_07_17_563Z-debug.log
Found npm debug log, make sure the path matches with the one in npm's output: C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\npm-cache\_logs\2021-10-05T10_07_17_563Z-debug.log
0 info it worked if it ends with ok
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' ]
2 info using npm@5.6.0
3 info using node@v8.9.4
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle projectname@0.1.0~prebuild: projectname@0.1.0
6 info lifecycle projectname@0.1.0~build: projectname@0.1.0
7 verbose lifecycle projectname@0.1.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle projectname@0.1.0~build: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;D:\agent\_work\11\s\node_modules\.bin;D:\agent\externals\vstsom;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;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\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files\dotnet\;C:\Program Files\nodejs\;C:\Windows\ServiceProfiles\NetworkService\.dotnet\tools;D:\agent\bin;D:\agent\bin
9 verbose lifecycle projectname@0.1.0~build: CWD: D:\agent\_work\11\s
10 silly lifecycle projectname@0.1.0~build: Args: [ '/d /s /c', 'react-scripts build' ]
11 silly lifecycle projectname@0.1.0~build: Returned: code: 1  signal: null
12 info lifecycle projectname@0.1.0~build: Failed to exec build script
13 verbose stack Error: projectname@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:285:16)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at EventEmitter.emit (events.js:214:7)
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 emitTwo (events.js:126:13)
13 verbose stack     at ChildProcess.emit (events.js:214:7)
13 verbose stack     at maybeClose (internal/child_process.js:925:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
14 verbose pkgid projectname@0.1.0
15 verbose cwd D:\agent\_work\11\s
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 v8.9.4
19 verbose npm  v5.6.0
20 error code ELIFECYCLE
21 error errno 1
22 error projectname@0.1.0 build: `react-scripts build`
22 error Exit status 1
23 error Failed at the projectname@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 ]
Error: C:\Program Files\nodejs\npm.cmd failed with return code: 1

我尝试添加一个 npm 缓存清理步骤,但没有任何区别。

我尝试在构建命令中增加内存,但这似乎没有任何区别。

当我在 Powershell 中本地尝试 npm run build 时,它会创建一个构建,我可以手动将其复制到运行它的服务器。

我在本地运行节点 11.15,TFS 服务器是 14.18。

TFS 在本地,但我无法通过 TFS Web 界面访问服务器。

有人对为什么会发生此错误有任何建议吗?

【问题讨论】:

【参考方案1】:

互联网上的大多数帖子都是关于节点的版本。我仔细检查了 TFS 服务器,它只有节点 8(!)。升级到 11.15 修复了我在上面看到的错误。

我现在有一个新错误 - 但这个错误已通过升级修复。

【讨论】:

以上是关于TFS:构建 React 项目失败的主要内容,如果未能解决你的问题,请参考以下文章

从 TFS Build 构建 MSI

构建失败'配置项目':react-native-reanimated'时出现问题。在 React 原生项目中

构建失败并在 TFS 中出现 COMPILETODALVIK 错误,但它在我的本地计算机中正确构建

即使安装了 Microsoft.Net.Compilers,C# 6.0 构建也会在 TFS 构建上失败

ASP.NET MVC 1.0 AfterBuilding 视图在 TFS 构建上失败

从 github 打开 react-native 项目时构建失败