React Native Azure Pipeline iOS构建失败(错误码65)求助
问题概述
React Native项目本地iOS构建、打包上传TestFlight均正常,但Azure Pipeline使用macOS-14虚拟机执行Xcode构建时失败,核心报错如下:
Node found at: /Users/adarsh/.nvm/versions/node/v20.18.1/bin/node
/Users/runner/work/1/s/ios/Pods/../../node_modules/react-native/ReactCommon/../scripts/react_native_pods_utils/script_phases.sh: line 34: /Users/adarsh/.nvm/versions/node/v20.18.1/bin/node: No such file or directory
Command PhaseScriptExecution failed with a nonzero exit code
失败的构建任务是React-rncore的Generate Specs脚本,最终导致xcodebuild返回码65。
问题原因
报错路径指向本地用户adarsh的NVM Node目录,但Azure流水线运行环境的用户是runner,该路径不存在。本质是流水线未正确配置Node环境,或Pod安装时缓存了本地的Node绝对路径,导致构建脚本无法找到正确的Node可执行文件。
解决方案
1. 显式安装指定版本的Node.js
在Xcode构建任务前添加Node安装步骤,确保流水线使用项目所需的Node版本,且路径被正确加入环境变量:
- task: NodeTool@0 inputs: versionSpec: '20.18.1' displayName: 'Install Node.js'
2. 重新安装依赖与CocoaPods
清除本地缓存的依赖和Pod配置,基于流水线环境重新安装,避免残留本地路径:
- script: | rm -rf node_modules npm install displayName: 'Clean and install npm dependencies' - script: | cd ios pod deintegrate pod install --repo-update displayName: 'Reinstall CocoaPods'
3. 确保Xcode任务环境变量包含Node路径
在Xcode任务中添加环境变量,强制指定Node路径,避免脚本找不到可执行文件:
- task: Xcode@4 displayName: Xcode build (signed) inputs: # 保留原有配置... env: PATH: $(PATH):$(Agent.HomeDirectory)/.nvm/versions/node/20.18.1/bin
修改后的完整YAML示例
- job: Phase_2 displayName: iOS Build cancelTimeoutInMinutes: 0 pool: name: Azure Pipelines vmImage: macOS-14 steps: - checkout: self - task: NodeTool@0 inputs: versionSpec: '20.18.1' displayName: 'Install Node.js' - script: | rm -rf node_modules npm install displayName: 'Clean and install npm dependencies' - script: | cd ios pod deintegrate pod install --repo-update displayName: 'Reinstall CocoaPods' - task: Xcode@4 displayName: Xcode build (signed) inputs: actions: clean configuration: 'Release' xcWorkspacePath: $(APPCENTER_XCODE_PROJECT) scheme: SynertrexIQ xcodeDeveloperDir: /Applications/Xcode_15.4.app/Contents/Developer packageApp: true provisioningProfileUuid: '$(AppProvisioningProfileUUID)' signingIdentity: '$(CodeSignIdentity)' exportTeamId: 'RQNV4QG7X5' archivePath: $(agent.builddirectory)/output/build/archive exportPath: $(agent.builddirectory)/output/build/export signingOption: 'manual' outputPattern: $(agent.builddirectory)/output/build env: PATH: $(PATH):$(Agent.HomeDirectory)/.nvm/versions/node/20.18.1/bin
内容的提问来源于stack exchange,提问作者Apavaiya

