I am very new to NextJS and deploying my first app onto Azure. Although the deployment is successful but I am unable to load the website. I get loads of 404 for JS, CSS and image files.
The path of static file seems to be referring to "_next/static" but "_next" directory has not been deployed. I am copying my yml and nextJS.config files.
Also, what should be the "physical path" of Virtual path inside Azure Configuration setting?
url is : https://friendsofthecommunity-gna8amh6cdfvcwd0.centralindia-01.azurewebsites.net/
name: Build and deploy Next.js app to Azure Web App
on: push: branches: - mainworkflow_dispatch:
env: APPLICATION_PUBLISH_PROFILE: ${{ secrets.xxxxxxxxxxxxxx }} WEBAPP_NAME: "xxxxxxxx"
jobs: build: runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Node.js version
uses: actions/setup-node@v4
with:
node-version: "20.x"
- name: npm install, build, and test
run: |
npm install
npm run build
mv ./build/static ./build/standalone/build
mv ./app ./build/standalone
mv ./next ./build/standalone
- name: "Deploy to Azure Web App"
id: deploy-to-webapp
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.WEBAPP_NAME }}
slot-name: "Production"
publish-profile: ${{ env.APPLICATION_PUBLISH_PROFILE }}
package: ./build/standalone
/** @type {import('next').NextConfig} */ const nextConfig = { reactStrictMode: true, distDir: 'build', output: 'standalone', };
module.exports = nextConfig;
2
Answers
Move to latest version of NextJS and use the Github templates for deployment
I tried your
next.config.mjs
configuration as shown below, but I got the same error:To reslove it remove the following below lines from your YAML file:
Then, update your YAML file as shown below.
Additionally, add the Startup Command to
node server.js
in the Configuration.There is no need to add/change physical path in Virtual path.Deployment status:
Output:
For Windows, use the YAML configuration shown below. Refer to this git for the complete YAML file.