Next.js 14 + VPS : Module path aliases won't work in Production (but work in development)
Unanswered
Africanized honey bee posted this in #help-forum
Africanized honey beeOP
When I try to run next build in developpement everything works perfectly.
However in production, I always have my module imported with ts path aliases not found
Here is my
The following docker file:
yarn build fails and raises Module not found: Can't resolve '@/components/Buttons/OverlayButtons' . I use app folder structure without src folder et my component folder is in the root folder. My version is NextJS 14.2.3.
I have already tried multiple solutions: https://stackoverflow.com/questions/76676456/next-js-v13-in-docker-does-not-respect-path-alias-but-works-locally
However in production, I always have my module imported with ts path aliases not found
Here is my
tsconfig:{
"compilerOptions": {
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": false,
"noEmitOnError": false,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"target": "esnext",
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": [
"./*"
],
}
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts"
],
"exclude": [
"node_modules"
]
}The following docker file:
FROM node
WORKDIR /workspace/frontend
ENV NODE_ENV=production
COPY package.json yarn.lock /workspace/frontend/
RUN yarn install
COPY . /workspace/frontend/
# Copy .env.production to .env.local as next read only this file
COPY .env.production /workspace/frontend/.env.local
RUN yarn build
CMD [ "yarn", "start" ]yarn build fails and raises Module not found: Can't resolve '@/components/Buttons/OverlayButtons' . I use app folder structure without src folder et my component folder is in the root folder. My version is NextJS 14.2.3.
I have already tried multiple solutions: https://stackoverflow.com/questions/76676456/next-js-v13-in-docker-does-not-respect-path-alias-but-works-locally