Open Hx-Regex opened 1 week ago
I defined a new nextjs project gave exactly your next config, and then used the same Dockerfile
as you mentioned above and my application builds smoothly with the button and input imported using @alias in the page.tsx
, No issue No errors, If you could provide some more info about your configurations, Maybe I'll be able to help out.
Maybe your components.json
is different if you can provide that, maybe could help you solve this.
Used the input component and the same dockerfile as you! Still not able to reproduce if you can give me something else that might be the cause of the issue cause looks like the regular config doesn't have the same issue!
@its-azharmalik thanks for the help here is my components.json i removed all the @ and the app run just fine with docker maybe its my fault i changed something when i started developing the app and forgot
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "new-york",
"rsc": true,
"tsx": true,
"tailwind": {
"config": "tailwind.config.ts",
"css": "app/globals.css",
"baseColor": "neutral",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils",
"ui": "@/components/ui",
"lib": "@/lib",
"hooks": "@/hooks"
}
}
Describe the bug
I'm experiencing an issue where my Next.js application builds successfully locally and on Vercel, but fails when attempting to build using Docker. The build process in Docker results in module resolution errors, specifically related to path aliases.
**Build Error Logs:
Steps to Reproduce: Local Build:
Run npm run build locally. Result: Builds successfully. Vercel Deployment:
Deploy the application to Vercel. Result: Deploys and works fine. Docker Build:
Use the provided Dockerfile to build the Docker image. Command: docker build -t projectD . Result: Fails with module resolution errors as shown in the logs.
The Docker build fails during the npm run build step with errors indicating that certain modules cannot be resolved, specifically those using the @ path alias.
**Configuration Files:
Set environment variables
ENV NODE_ENV=production
Set the working directory
WORKDIR /app
Copy package.json and package-lock.json
COPY package*.json ./
Install all dependencies (including devDependencies)
RUN npm install
Copy the rest of the application code
COPY . .
Build the Next.js app
RUN npm run build
Remove devDependencies to reduce image size
RUN npm prune --production
Expose the port the app runs on
EXPOSE 3000
Define the command to run the app
CMD ["npm", "start"]
System Info
Before submitting
I'm seeking help to identify why the Docker build process cannot resolve modules using the @ path alias, despite the application building successfully in other environments. If additional information is required, I can provide further details such as complete project structure, additional configuration files, or logs (I've found exisiting issues but didn't fix my problem)