Azure App Service部署React应用失败求助:Node.js版本检测异常
问题定位与解决方案
核心问题
你上传的是React项目编译后的build文件夹,但Azure的Oryx工具默认执行远程构建流程——它需要读取项目源码中的package.json来检测Node.js版本并执行构建命令,但build文件夹里只有静态编译文件,没有源码文件,因此触发Couldn't detect a version for the platform 'nodejs' in the repo错误。
解决方案
方案1:关闭远程构建,直接部署静态文件
这是适配你当前场景(已本地完成构建)的最优方案:
- 通过Azure门户配置:
- 进入你的App Service资源 → 左侧菜单选择「配置」→ 「常规设置」
- 找到「启用生成自动化」选项,切换为「关闭」
- 或在「应用程序设置」标签页添加新配置:
- 名称:
SCM_DO_BUILD_DURING_DEPLOYMENT - 值:
false
- 名称:
- 保存配置后重新部署
build文件夹
- 通过VS Code配置:
在项目的.vscode/settings.json中添加以下内容,部署时跳过构建步骤:{ "appService.zipDeploy.skipBuild": true }
方案2:上传完整项目源码(如需远程构建)
如果希望Azure自动完成构建流程,不要只传build文件夹,需上传整个项目源码(包含package.json),并在package.json中明确指定Node.js版本:
在package.json根节点添加:
"engines": { "node": ">=18.x" }
这样Oryx就能正确识别Node.js版本并执行npm run build完成构建。
附用户提供的原始信息
错误提示
4:29:02 PM 1001GoldService: Deployment Failed. deployer = ms-azuretools-vscode deploymentPath = ZipDeploy. Extract zip. Remote build.
4:29:09 PM 1001GoldService: Deployment failed.
package.json内容
{ "name": "my-app", "version": "0.1.0", "private": true, "dependencies": { "@testing-library/jest-dom": "^5.17.0", "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^13.5.0", "react": "^18.2.0", "react-dom": "^18.2.0", "react-router-dom": "^6.22.1", "react-scripts": "5.0.1", "sfcookies": "^1.0.2", "web-vitals": "^2.1.4" }, "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" }, "eslintConfig": { "extends": [ "react-app", "react-app/jest" ] }, "browserslist": { "production": [ ">0.2%", "not dead", "not op_mini all" ], "development": [ "last 1 chrome version", "last 1 firefox version", "last 1 safari version" ] } }
完整部署日志
4:28:54 PM 1001GoldService: Starting deployment... 4:28:54 PM 1001GoldService: Creating zip package... 4:28:55 PM 1001GoldService: Zip package size: 2.2 MB 4:28:54 PM 1001GoldService: Fetching changes. 4:28:55 PM 1001GoldService: Cleaning up temp folders from previous zip deployments and extracting pushed zip file /tmp/zipdeploy/2834e240-ff72-469e-9de0-c8114be6ebc3.zip (2.10 MB) to /tmp/zipdeploy/extracted 4:28:57 PM 1001GoldService: Updating submodules. 4:28:58 PM 1001GoldService: Preparing deployment for commit id 'e8191abd-2'. 4:28:59 PM 1001GoldService: PreDeployment: context.CleanOutputPath False 4:28:59 PM 1001GoldService: PreDeployment: context.OutputPath /home/site/wwwroot 4:28:59 PM 1001GoldService: Repository path is /tmp/zipdeploy/extracted 4:28:59 PM 1001GoldService: Running oryx build... 4:28:59 PM 1001GoldService: Command: oryx build /tmp/zipdeploy/extracted -o /home/site/wwwroot --platform nodejs --platform-version 18 -p virtualenv_name= --log-file /tmp/build-debug.log -i /tmp/8dc37a8d19f24d9 -p compress_node_modules=tar-gz | tee /tmp/oryx-build.log 4:29:00 PM 1001GoldService: Operation performed by Microsoft Oryx, https://github.com/Microsoft/Oryx 4:29:00 PM 1001GoldService: You can report issues at https://github.com/Microsoft/Oryx/issues 4:29:00 PM 1001GoldService: Oryx Version: 0.2.20230508.1, Commit: 7fe2bf39b357dd68572b438a85ca50b5ecfb4592, ReleaseTagName: 20230508.1 4:29:00 PM 1001GoldService: Build Operation ID: 01877ae608ca5bb9 4:29:00 PM 1001GoldService: Repository Commit : e8191abd-253a-4dd7-8bc3-cccc87557b95 4:29:00 PM 1001GoldService: OS Type : bullseye 4:29:00 PM 1001GoldService: Image Type : githubactions 4:29:00 PM 1001GoldService: Detecting platforms... 4:29:00 PM 1001GoldService: Could not detect any platform in the source directory. 4:29:00 PM 1001GoldService: Error: Couldn't detect a version for the platform 'nodejs' in the repo. 4:29:01 PM 1001GoldService: /bin/bash -c "oryx build /tmp/zipdeploy/extracted -o /home/site/wwwroot --platform nodejs --platform-version 18 -p virtualenv_name= --log-file /tmp/build-debug.log -i /tmp/8dc37a8d19f24d9 -p compress_node_modules=tar-gz | tee /tmp/oryx-build.log ; exit $PIPESTATUS " 4:29:01 PM 1001GoldService: Generating summary of Oryx build 4:29:01 PM 1001GoldService: Parsing the build logs 4:29:01 PM 1001GoldService: Found 0 issue(s) 4:29:01 PM 1001GoldService: Build Summary : 4:29:01 PM 1001GoldService: =============== 4:29:02 PM 1001GoldService: Errors (0) 4:29:02 PM 1001GoldService: Warnings (0) 4:29:02 PM 1001GoldService: Deployment Failed. deployer = ms-azuretools-vscode deploymentPath = ZipDeploy. Extract zip. Remote build. 4:29:09 PM 1001GoldService: Deployment failed.
内容的提问来源于stack exchange,提问作者Руслан Василев
相关产品推荐
相关产品推荐

