I have this NextJS app being deployed to an Azure App Service (Linux), using local images (everything into /public
).
While running the app locally (with npm run dev
) or building + starting it locally (npm run build
and npm start
), everything works fine, images are rendered as expected, BUT
when I deploy it to Azure, via Github Actions, the app is running but the only images that get rendered are the .webp
. All my .png
are broken.
I have researched a lot and I tried a LOT of things from Stack Overflow and others, but no success.
- I checked for letters casing in the filenames
- I tried importing the images pointing to the
/public
folder (eg.import Image1 from '../../public/images;my-image.png
) - I tried using
<Image />
with relative import to public folder (eg.<Image src="/images/my-image.png" />
) and with static import. - I tried adding
sharp
in my project dependencies - I tried using
<img />
with relative import to public folder (eg.<img src="/images/my-image.png" />
) and with static import
This is my next.config.js
:
const withImages = require("next-images");
/** @type {import('next').NextConfig} */
const nextConfig = withImages({
reactStrictMode: true,
pageExtensions: ["tsx"],
images: {
formats: ["image/webp", "image/avif"],
domains: ["my-app-url.azurewebsites.net/"],
},
});
module.exports = nextConfig;
This is my pipeline yml:
# 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
on:
push:
branches:
- develop
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Node.js version
uses: actions/setup-node@v3
with:
node-version: "18.x"
- name: npm install, build, and test
run: |
npm install
npm run build --if-present
npm run test --if-present
- name: Zip all files for upload between jobs
run: zip next.zip ./* .next -qr
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v3
with:
name: node-app
path: next.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@v3
with:
name: node-app
- name: "Deploy to Azure Web App"
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: "my-app-name"
slot-name: "Production"
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE }}
package: next.zip
- name: Delete zip file
run: rm next.zip
And I tried a couple things more that I can't remember anymore right now, but NOTHING worked so far.
The funny thing is the fact that the .webp
images are working while PNGs are not.
I don't know what to do anymore, may anyone give me some light here?