Azure Web App failing
Please Help me with the following -
I have been trying to deploy my reactjs application on Azure Web App using GitHub actions.
While I have been trying to deploy, though the deployment is successful, but however my application isnt running and I am getting error on the Log Stream for the particular Web App.
My App have been deployed on PORT 8080 -
in Package.json
"scripts": {
"start": "cross-env PORT=8080 react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
in Dockerfile
# Use an official Node.js runtime as a parent image
FROM node:14
# Set the working directory
WORKDIR /app
# Copy package.json and package-lock.json
COPY package*.json ./
# Install dependencies
RUN npm install
# Copy the rest of the application code
COPY . .
# Build the React app
RUN npm run build
# Serve the React app using a simple server
RUN npm install -g serve
CMD ["serve", "-s", "build"]
# Expose the port the app runs on
EXPOSE 8080
And I have also tested it on localhost and have got the response.
But upon deployment below are the log
Following Measures Taken:
- Startup Command set to "npm start"
- Configured the port - Application settings
SCM_DO_BUILD_DURING_DEPLOYMENT = 1
WEBSITES_PORT = 8080 - Restarted the App Service
- Checked Networking Settings
Azure App Service
Azure Static Web Apps
-
Shree Hima Bindu Maganti 1,585 Reputation points • Microsoft Vendor
2024-11-27T02:35:48.37+00:00 Hi @Ayushi Soni (Contractor) ,
Welcome to the Microsoft Q&A Platform!
The issue indicates that while the React app deploys successfully to your Azure Web App, it's not starting properly due to an environment configuration or runtime error. Based on the logs and the provided configurations,
The error "MODULE_NOT_FOUND" suggests that a required dependency isn't available in the environment.- All necessary dependencies are listed in your
package.json
. - You're using
npm ci
instead ofnpm install
in production environments to ensure consistency in dependency versions. - Your Dockerfile uses
serve
to serve the React app. This setup is fine for static hosting but doesn’t account for dynamically setting the port via Azure App Service. Update your Dockerfile to dynamically read the port:# Use an official Node.js runtime as a parent image FROM node:14 # Set the working directory WORKDIR /app # Copy package.json and package-lock.json COPY package*.json ./ # Install dependencies RUN npm install # Copy the rest of the application code COPY . . # Build the React app RUN npm run build # Install a server RUN npm install -g serve # Use the PORT environment variable from Azure, default to 8080 CMD ["serve", "-s", "build", "-l", "${PORT:-8080}"] # Expose the port the app runs on EXPOSE 8080
- Azure App Service tries to interpret the
npm start
command when theStartup Command
is set, but this can conflict with your Dockerfile. TheCMD
directive in your Dockerfile already specifies the startup process (serve -s build
). Remove theStartup Command
setting from the Azure portal to avoid conflicts. - Make sure the following environment variables are set in your Azure App Service Configuration > Application settings:
-
WEBSITES_PORT
=8080
(required for Docker containers in App Service) -
PORT
=8080
(used by your app to listen on the correct port)
-
- The
SCM_DO_BUILD_DURING_DEPLOYMENT=1
flag works for Azure's Oryx build system. 6. Since you're using a custom Dockerfile, you don't need this flag. Remove it from your Application Settings. - If your app is exposed on port
8080
but still inaccessible, check the following:- Verify that your app service is set to Linux (if using Docker).
- Ensure that no restrictions in Networking are blocking traffic to/from your app.
- To confirm your Dockerfile works, build and test it locally
docker build -t my-react-app . docker run -p 8080:8080 my-react-app```dockerfile
Apply the suggested changes and redeploy your application. If issues still exists, let me know with an updated log snippet for further analysis. [https://learn.microsoft.com/en-us/azure/app-service/tutorial-custom-container?tabs=azure-cli&pivots=container-linux](https://learn.microsoft.com/en-us/azure/app-service/tutorial-custom-container?tabs=azure-cli&pivots=container-linux) If the answer is helpful, please click "**Accept Answer**" and kindly upvote it.
- All necessary dependencies are listed in your
-
Shree Hima Bindu Maganti 1,585 Reputation points • Microsoft Vendor
2024-11-28T04:35:34.17+00:00 Hi @Ayushi Soni (Contractor) ,
Following up to see if you have chance to check my previous response and help us with requested information to check and assist you further on this.
-
Shree Hima Bindu Maganti 1,585 Reputation points • Microsoft Vendor
2024-11-29T04:53:44.3866667+00:00 Hi @Ayushi Soni (Contractor) ,
Following up to see if you have chance to check my previous response and help us with requested information to check and assist you further on this.
-
Ayushi Soni (Contractor) 0 Reputation points
2024-12-02T13:34:48.62+00:00 - All necessary dependencies are listed in your
package.json
. - I am able to build it locally so this is not the issue - You're using
npm ci
instead ofnpm install
in production environments to ensure consistency in dependency versions. - should I change it in docker file? - Update my Dockerfile
- Removed the
Startup Command
setting from the Azure portal to avoid conflicts. -
WEBSITES_PORT
=8080
(required for Docker containers in App Service) Added -
SCM_DO_BUILD_DURING_DEPLOYMENT=1
flag removed - If your app is exposed on port
8080
but still inaccessible, check the following:- Verify that your app service is set to Linux (if using Docker). - I am using nodejs 20
- Ensure that no restrictions in Networking are blocking traffic to/from your app. - not sure How to check it. Please elaborate
- All necessary dependencies are listed in your
-
Ayushi Soni (Contractor) 0 Reputation points
2024-12-02T13:37:21.71+00:00 I tried it but getting same error
-
Ayushi Soni (Contractor) 0 Reputation points
2024-12-02T13:38:03.5+00:00 I tried it. Getting same error
-
Shree Hima Bindu Maganti 1,585 Reputation points • Microsoft Vendor
2024-12-03T04:20:19.5633333+00:00 Hi @Ayushi Soni (Contractor) ,
Thankyou for Your Response.
npm ci is recommended for production environments as it installs dependencies exactly as listed in package-lock.json, ensuring consistency. This is particularly useful for CI/CD pipelines.
switching to
npm install
if:- Your
package-lock.json
is outdated or not present. - You need to fetch the latest versions of dependencies dynamically.
- If your local build works, it’s better to stick with
npm ci
unless you suspect a lock file issue.
Updated Dockerfile Make sure your Dockerfile includes the correct steps. For a Node.js 20 app exposed on port 8080:
FROM node:20 # Create app directory WORKDIR /usr/src/app # Install app dependencies COPY package*.json ./ RUN npm ci --only=production # Copy app source code COPY . . # Expose port EXPOSE 8080 # Start the application CMD ["npm", "start"]
- Checking Networking Restrictions To ensure no network issues are blocking traffic to/from your app.
- Verify App Service Access:
- Go to Azure Portal > Your App Service > Networking > Access Restrictions.
- Ensure there are no inbound or outbound restrictions that prevent access to port 8080 or traffic from external sources.
- Use Diagnose and Solve Problems in the Azure Portal under the App Service settings.
- Search for "Networking" diagnostics to see if there's a specific networking-related error.
- NSG and Firewall Rules.
- If your app is behind a virtual network, check the Network Security Group (NSG) rules and ensure port 8080 is allowed.
- Verify firewall configurations in your subscription to ensure traffic isn't blocked.
- Set
WEBSITES_PORT=8080
in Azure App Service > Configuration > Application Settings. - Ensure your app listens explicitly on port
8080
by configuring it in your Node.js server .
const express = require('express'); const app = express(); const port = process.env.PORT || 8080; app.get('/', (req, res) => res.send('Hello World!')); app.listen(port, () => console.log(`Server running on port ${port}`));
- Check Azure's
Log Stream
for deployment errors. - Test with Postman or Curl: Verify app accessibility via
http://<app-name>.azurewebsites.net
.
https://learn.microsoft.com/en-us/azure/app-service/configure-language-nodejs?pivots=platform-linux
https://learn.microsoft.com/en-us/azure/app-service/deploy-github-actions?tabs=openid%2Caspnetcore
- Your
-
Shree Hima Bindu Maganti 1,585 Reputation points • Microsoft Vendor
2024-12-04T07:08:07.1233333+00:00 Hi @Ayushi Soni (Contractor) ,
Following up to see if you have chance to check my previous response and help us with requested information to check and assist you further on this.
-
Shree Hima Bindu Maganti 1,585 Reputation points • Microsoft Vendor
2024-12-05T01:32:50.1866667+00:00 Hi @Ayushi Soni (Contractor) ,
Following up to see if you have chance to check my previous response and help us with requested information to check and assist you further on this.
-
Ayushi Soni (Contractor) 0 Reputation points
2024-12-06T09:17:28.92+00:00 @Shree Hima Bindu Maganti
After trying all the above options
I can't reduce the node version due to some of the libraries.In App Logs we are getting-
Command: oryx build /tmp/zipdeploy/extracted -o /home/site/wwwroot --platform nodejs --platform-version 20 -p virtualenv_name= --log-file /tmp/build-debug.log -i /tmp/8dd15ca2faa5f9c -p compress_node_modules=tar-gz | tee /tmp/oryx-build.logOperation performed by Microsoft Oryx, https://github.com/Microsoft/Oryx
You can report issues at https://github.com/Microsoft/Oryx/issues
Oryx Version: 0.2.20240424.1, Commit: d37b2225a252ab2c04b4726024d047cf01ea1318, ReleaseTagName: 20240424.1
Build Operation ID: 7e2dad43d85ac3dd
Repository Commit : e140809b-0c7d-446e-bec2-781f59437c61
OS Type : bookworm
Image Type : githubactions
Detecting platforms...
Detected following platforms:
nodejs: 20.18.0
python: 3.8.18
php: 8.3.12
Version '20.18.0' of platform 'nodejs' is not installed. Generating script to install it...
Version '3.8.18' of platform 'python' is not installed. Generating script to install it...
Version '8.3.12' of platform 'php' is not installed. Generating script to install it...
Detected the following frameworks: React
Using intermediate directory '/tmp/8dd15ca2faa5f9c'.
Copying files to the intermediate directory...
Done in 1 sec(s).
Source directory : /tmp/8dd15ca2faa5f9c
Destination directory: /home/site/wwwroot
Downloading and extracting 'nodejs' version '20.18.0' to '/tmp/oryx/platforms/nodejs/20.18.0'...
Detected image debian flavor: bookworm.
Downloaded in 1 sec(s).
Verifying checksum...
Extracting contents...
performing sha512 checksum for: nodejs...
Done in 2 sec(s).
Downloading and extracting 'python' version '3.8.18' to '/tmp/oryx/platforms/python/3.8.18'...
Detected image debian flavor: bookworm.
Downloaded in 1 sec(s).
Verifying checksum...
Extracting contents...
performing sha512 checksum for: python...
Done in 3 sec(s).
Downloading and extracting 'php' version '8.3.12' to '/tmp/oryx/platforms/php/8.3.12'...
Detected image debian flavor: bookworm.
Downloaded in 1 sec(s).
Verifying checksum...
Extracting contents...
performing sha512 checksum for: php...
Done in 1 sec(s).
Downloading and extracting 'php-composer' version '2.6.2' to '/tmp/oryx/platforms/php-composer/2.6.2'...
Detected image debian flavor: bookworm.
Downloaded in 0 sec(s).
Verifying checksum...
Extracting contents...
performing sha512 checksum for: php-composer...
Done in 0 sec(s).
Removing existing manifest file
Creating directory for command manifest file if it does not exist
Creating a manifest file...
Node Build Command Manifest file created.
Using Node version:
v20.18.0
Using Npm version:
10.8.2
Running 'npm install'...
npm warn deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
npm warn deprecated @babel/plugin-proposal-nullish-coalescing-operator@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.
npm warn deprecated @babel/plugin-proposal-private-methods@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-private-methods instead.
npm warn deprecated @babel/plugin-proposal-class-properties@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
npm warn deprecated @babel/plugin-proposal-numeric-separator@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-numeric-separator instead.
npm warn deprecated rollup-plugin-terser@7.0.2: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-terser
npm warn deprecated @humanwhocodes/config-array@0.13.0: Use @eslint/config-array instead
npm warn deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
npm warn deprecated abab@2.0.6: Use your platform's native atob() and btoa() methods instead
npm warn deprecated @babel/plugin-proposal-private-property-in-object@7.21.11: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-private-property-in-object instead.
npm warn deprecated @babel/plugin-proposal-optional-chaining@7.21.0: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.
npm warn deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm warn deprecated @humanwhocodes/object-schema@2.0.3: Use @eslint/object-schema instead
npm warn deprecated domexception@2.0.1: Use your platform's native DOMException instead
npm warn deprecated w3c-hr-time@1.0.2: Use your platform's native performance.now() and performance.timeOrigin.
npm warn deprecated q@1.5.1: You or someone you depend on is using Q, the JavaScript Promise library that gave JavaScript developers strong feelings about promises. They can almost certainly migrate to the native JavaScript promise now. Thank you literally everyone for joining me in this bet against the odds. Be excellent to each other.
npm warn deprecated
npm warn deprecated (For a CapTP with native promises, see @endo/eventual-send and @endo/captp)
npm warn deprecated sourcemap-codec@1.4.8: Please use @jridgewell/sourcemap-codec instead
npm warn deprecated workbox-cacheable-response@6.6.0: workbox-background-sync@6.6.0
npm warn deprecated workbox-google-analytics@6.6.0: It is not compatible with newer versions of GA starting with v4, as long as you are using GAv3 it should be ok, but the package is not longer being maintained
npm warn deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x.
npm warn deprecated eslint@8.57.1: This version is no longer supported. Please see https://eslint.org/version-support for other options.
added 1602 packages, and audited 1603 packages in 19s
290 packages are looking for funding
run
npm fund
for details8 vulnerabilities (2 moderate, 6 high)
To address all issues (including breaking changes), run:
npm audit fix --force
Run
npm audit
for details.Running 'npm run build'...
paccarui@0.1.0 build
react-scripts build
Creating an optimized production build...
Compiled successfully.
File sizes after gzip:
383.67 kB (+78 B) build/static/js/main.8ff44e4b.js
1.85 kB build/static/css/main.8ad59c94.css
1.77 kB build/static/js/845.e9a461ce.chunk.js
The project was built assuming it is hosted at /.
You can control this with the homepage field in your package.json.
The build folder is ready to be deployed.
You may serve it with a static server:
npm install -g serve
serve -s build
Find out more about deployment here:
Zipping existing node_modules folder...
Done in 13 sec(s).
Preparing output...
Copying files to destination directory '/home/site/wwwroot'...
Done in 2 sec(s).
Removing existing manifest file
Creating a manifest file...
Manifest file created.
Copying .ostype to manifest output directory.
Done in 65 sec(s).
-
Shree Hima Bindu Maganti 1,585 Reputation points • Microsoft Vendor
2024-12-12T16:23:33.0866667+00:00 Hi @Ayushi Soni (Contractor) ,
Thankyou for Your Response.
The log indicates that your React application builds successfully, but the deployment process might encounter issues related to the Node.js environment or the app’s configuration.- Ensure the Azure App Service uses the correct Node.js version.
- Go to Azure Portal > App Service > Configuration > General Settings.
- Set the Runtime Stack to Node.js 20.x.
Set the startup command to serve the React app in Single Page Application mode. - Go to Azure Portal > App Service > Configuration > General Settings > Startup Command.
pm2 serve /home/site/wwwroot --no-daemon --spa
- Update the
package.json
file based on your app’s deployment path."homepage": "/"
- For subpath hosting.
"homepage": "/app"
- Rebuild the application after making this change.
npm run build
- Run these commands locally to fix dependency issues.
npm audit fix
npm audit fix --force
- Rebuild the app to ensure the updated dependencies are included.
npm run build
- Enable detailed logs in Azure to identify deployment issues.
- Go to Azure Portal > App Service > Monitoring > App Service Logs.
- Turn on Application Logging and set the level to Verbose.
- Create a custom startup script to bypass Oryx. Add a
startup.sh
file to your project with the following content.#!/bin/bash
cd /home/site/wwwroot
pm2 serve build --no-daemon --spa
- Set the script as the startup command in App Service Configuration > Startup Command.
./startup.sh
https://learn.microsoft.com/en-us/azure/app-service/
https://pm2.keymetrics.io/docs/usage/restart-strategies/
-
Shree Hima Bindu Maganti 1,585 Reputation points • Microsoft Vendor
2024-12-14T15:56:43.14+00:00 Hi @Ayushi Soni (Contractor) ,
Following up to see if you have chance to check my previous response and help us with requested information to check and assist you further on this.
-
Shree Hima Bindu Maganti 1,585 Reputation points • Microsoft Vendor
2024-12-16T17:00:36.04+00:00 Hi @Ayushi Soni (Contractor) ,
Following up to see if you have chance to check my previous response and help us with requested information to check and assist you further on this.
Sign in to comment