Hello @Luay Sharqiya,
To resolve your GitHub Actions deployment issue for a Node.js/React app on Azure Web App, ensure that your Azure settings are correctly configured.
In the Azure Portal, navigate to your Web App’s Configuration settings and set the stack to Node 20.
Additionally, update the Start Command as follows:
- If using Create React App, set it to:
npm start
asnpx serve -s build
Below is my sample deployment YAML file for a React app. Modify it accordingly:
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions
name: Build and deploy Node.js app to Azure Web App - sampath345
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read # Required for actions/checkout
steps:
- uses: actions/checkout@v4
- name: Set up Node.js version
uses: actions/setup-node@v3
with:
node-version: '20.x'
- name: Install dependencies, build, and test
run: |
npm install
npm run build --if-present
npm run test --if-present
- name: Zip artifact for deployment
run: zip release.zip ./* -r
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v4
with:
name: node-app
path: release.zip
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v4
with:
name: node-app
- name: Unzip artifact for deployment
run: unzip release.zip
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v3
with:
app-name: 'sampath345'
slot-name: 'Production'
package: release.zip
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_009C04A9BEB14A4DAA466C6AB81567A5 }}
Ensure your GitHub Actions workflow correctly installs dependencies, builds your React app, and deploys it to Azure.
In General Settings, set the Startup Command to:
pm2 serve /home/site/wwwroot/build --no-daemon
This is required when "start": "serve -s build"
is set in your package.json
file to properly run the app.
I hope this helps!
If you found this answer helpful, please click Accept Answer and consider upvoting it by clicking Yes.
If you have any further questions, feel free to click Comment.