Cannot find 'nuxt.mjs' during build in Dockerfile
Hey all,
I'm trying to build my Nuxt application via Docker, but my Dockerfile is giving me the following error:
This is my Dockerfile:
Building locally seems to work just fine, so I'm not sure what's causing this issue. Any help would be appreciated!
2 Replies
Hi @Viridian. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the error message and your Dockerfile, I can see you're encountering a common issue when building Nuxt applications in Docker. The error indicates that Docker can't find the
nuxt.mjs
file during the build process.
Looking at the knowledge sources, there are a few potential solutions:
Missing .dockerignore file
The most likely cause is that you're missing a .dockerignore
file, which is causing your local node_modules
folder to be copied over and interfering with the Docker build process. This exact issue was mentioned in a Stack Overflow post where the solution was adding a proper .dockerignore
file Stack Overflow Post > Docker Build Problem "Error: Cannot find module".
Create a .dockerignore
file in the same directory as your Dockerfile with the following content:
Other potential solutions
If adding the .dockerignore
file doesn't solve your issue, consider these alternatives:
1. Use shamefully-hoist=true
: In one of the knowledge sources, it was mentioned that some Nuxt modules might not work without the shamefully-hoist
flag. You're already using this in your Dockerfile, which is good.
2. Try a different package manager: Some users reported success by switching from one package manager to another. If pnpm continues to cause issues, you might try npm or yarn.
3. Use buildx
for cross-platform builds: If you're building for a different platform than your host, using docker buildx build
instead of docker build
might help, as mentioned in Stack Overflow Post > Nuxt build hanging when building in linux docker image.
4. Check your Nuxt version compatibility: Make sure your Nuxt version is compatible with the Node.js version you're using in your Dockerfile.
Let me know if adding the .dockerignore
file resolves your issue!
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@173158033742888961> Kapa.ai is still learning and improving, please let me know how I did by reacting below.