I've been trying to deploy my NextJS website to Azure App service, via github actions. But I keep getting this error at the build stage.
▲ Next.js 14.2.22
Creating an optimized *** build ...
Failed to compile.
./src/app/(pages)/(admin)/admin/events/[eventId]/edit/page.tsx
Module not found: Can't resolve '@/validation/event'
./src/app/(pages)/(admin)/admin/events/add/page.tsx
Module not found: Can't resolve '@/validation/event'
./src/app/(pages)/(admin)/admin/orders/[orderId]/page.tsx
Module not found: Can't resolve '@/app/components/checkout/checkoutProduct/checkoutProduct'
./src/app/(pages)/(admin)/admin/products/[productId]/edit/page.tsx
Module not found: Can't resolve '@/validation/product'
./src/app/(pages)/(admin)/admin/products/add/page.tsx
Module not found: Can't resolve '@/validation/product'
> Build failed because of webpack errors
Error: Process completed with exit code 1.
When I run npm run build
locally, it's working fine.
The files do exist in the appropriate folder, and there are no mistakes while importing them.
The tsconfig file is like this
{
"compilerOptions": {
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"],
"@/validation/*": ["./src/validation/*"],
"@/app/*": ["./src/app/*"],
"@/components/*": ["./src/app/components/*"]
}
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
"build/types/**/*.ts"
],
"exclude": [
"node_modules"
]
}
The workflow file is as follows
name: Build and deploy Next.js app to Azure Web App
on:
push:
branches:
- main
workflow_dispatch:
env:
NEXT_PUBLIC_BASE_URL: ${{ secrets.NEXT_PUBLIC_BASE_URL}}
DATABASE_URL: ${{ secrets.DATABASE_URL }}
REDIS_URL: ${{ secrets. REDIS_URL }}
REDIS_TOKEN: ${{ secrets.REDIS_TOKEN }}
NEXT_PUBLIC_RECAPTCHA_PUBLIC_KEY: ${{ secrets.NEXT_PUBLIC_RECAPTCHA_PUBLIC_KEY }}
RECAPTCHA_SECRET_KEY: ${{ secrets.RECAPTCHA_SECRET_KEY }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
NODE_ENV: ${{ secrets.NODE_ENV }}
NEXT_COMMUNICATION_SERVICES_CONNECTION_STRING: ${{ secrets.NEXT_COMMUNICATION_SERVICES_CONNECTION_STRING }}
NEXT_RAZORPAY_KEY_ID: ${{ secrets.NEXT_RAZORPAY_KEY_ID }}
NEXT_RAZORPAY_SECRET_KEY: ${{ secrets.NEXT_RAZORPAY_SECRET_KEY }}
APPLICATION_PUBLISH_PROFILE: ${{ secrets.APP_PUBLISH_PROFILE }}
WEBAPP_NAME: ${{ secrets.WEBAPP_NAME }}
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.16.0"
- name: npm install, build, and test
run: |
npm install
npm run build
mv ./build/static ./build/standalone/build
mv ./public ./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
My nextjs config file contains the following
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: false,
distDir: 'build',
output: 'standalone',
};
export default nextConfig;
I've searched around and couldn't find anything useful for my case. Please help me resolve this issue
I've tried updating the node version in the workflow file to the exact node version that I'm running locally. I've also tried enabling webpack5 in the next config file, which didn't help either.
I'd want the build step to work and complete successfully.
Github Repo: