Nuxt 4 build but doesn't work
[request error] [unhandled] [GET] http://10.244.208.129:3200/
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/app/.output/server/node_modules/unhead/dist/server.mjs' imported from /app/.output/server/chunks/routes/renderer.mjs
at finalizeResolution (node:internal/modules/esm/resolve:275:11)
... 6 lines matching cause stack trace ...
at ModuleJob._link (node:internal/modules/esm/module_job:175:49) {
cause: Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/app/.output/server/node_modules/unhead/dist/server.mjs' imported from /app/.output/server/chunks/routes/renderer.mjs
at finalizeResolution (node:internal/modules/esm/resolve:275:11)
at moduleResolve (node:internal/modules/esm/resolve:860:10)
at defaultResolve (node:internal/modules/esm/resolve:984:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:780:12)
at #cachedDefaultResolve (node:internal/modules/esm/loader:704:25)
at ModuleLoader.resolve (node:internal/modules/esm/loader:687:38)
at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:305:38)
at ModuleJob._link (node:internal/modules/esm/module_job:175:49) {
code: 'ERR_MODULE_NOT_FOUND',
url: 'file:///app/.output/server/node_modules/unhead/dist/server.mjs'
},
statusCode: 500,
fatal: false,
unhandled: true,
statusMessage: undefined,
data: undefined
}
[request error] [unhandled] [GET] http://10.244.208.129:3200/__nuxt_error?error=true&url=%2F&statusCode=500&statusMessage=Server+Error&message=Server+Error
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/app/.output/server/node_modules/unhead/dist/server.mjs' imported from /app/.output/server/chunks/routes/renderer.mjs
at finalizeResolution (node:internal/modules/esm/resolve:275:11)
... 6 lines matching cause stack trace ...
at ModuleJob._link (node:internal/modules/esm/module_job:175:49) {
cause: Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/app/.output/server/node_modules/unhead/dist/server.mjs' imported from /app/.output/server/chunks/routes/renderer.mjs
at finalizeResolution (node:internal/modules/esm/resolve:275:11)
at moduleResolve (node:internal/modules/esm/resolve:860:10)
at defaultResolve (node:internal/modules/esm/resolve:984:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:780:12)
at #cachedDefaultResolve (node:internal/modules/esm/loader:704:25)
at ModuleLoader.resolve (node:internal/modules/esm/loader:687:38)
at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:305:38)
at ModuleJob._link (node:internal/modules/esm/module_job:175:49) {
code: 'ERR_MODULE_NOT_FOUND',
url: 'file:///app/.output/server/node_modules/unhead/dist/server.mjs'
},
statusCode: 500,
fatal: false,
unhandled: true,
statusMessage: undefined,
data: undefined
}
5 Replies
Hi @flav. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
The error you're encountering:
indicates that the Nuxt build is trying to import the
This type of error often happens if the build process does not correctly include all required dependencies in the
If you are using Docker Compose and mounting your project directory as a volume, it can overwrite the
If the
Nuxt 4 uses Unhead v2, which has some breaking changes. However, the error you are seeing is not about API changes but about missing files. Still, ensure you are not using any removed props or features from Unhead v1, and that your dependencies are up to date. If you have compatibility issues, you can enable legacy mode in your
unhead
module on the server, but the file is missing from the output directory.
Based on the knowledge sources, here are some possible causes and solutions:
1. Missing Dependencies in OutputThis type of error often happens if the build process does not correctly include all required dependencies in the
.output
directory. This can occur if your node_modules
directory is not properly handled during Docker builds, or if files are being overwritten or omitted.
- In Docker environments, this can happen if you copy your local node_modules
into the container, which can conflict with the build process. Make sure you have a proper .dockerignore
file that excludes node_modules
so that the container installs dependencies fresh and does not copy over your local modules. This is a common cause of "Cannot find module" errors in Dockerized Nuxt apps Docker Build Problem "Error: Cannot find module".
2. Volume Mounts Overwriting OutputIf you are using Docker Compose and mounting your project directory as a volume, it can overwrite the
.output
directory generated during the build stage, resulting in missing files at runtime. Removing or adjusting the volume mounts in your docker-compose.yaml
can resolve this issue How to run Nuxt3 with docker (docker compose).
3. Build Process IssuesIf the
.output
directory is empty or missing files after running nuxt build
, it could be due to a misconfiguration or a corrupted project state. In some cases, users have resolved this by creating a fresh Nuxt project and carefully copying their files over, which suggests that subtle configuration or state issues can cause the build to fail to generate the correct output Nuxt3 build .output folder remains empty.
4. Unhead v2 MigrationNuxt 4 uses Unhead v2, which has some breaking changes. However, the error you are seeing is not about API changes but about missing files. Still, ensure you are not using any removed props or features from Unhead v1, and that your dependencies are up to date. If you have compatibility issues, you can enable legacy mode in your
nuxt.config
:
Unhead v2 Upgrade Guide
What you should do:
- Ensure your .dockerignore
excludes node_modules
and other build artifacts.
- Avoid mounting your project directory as a volume in production Docker Compose setups.
- Delete node_modules
and lock files, then reinstall dependencies and rebuild.
- If the problem persists, try generating a fresh Nuxt project and migrate your code.
If after these steps the issue remains, the knowledge sources do not provide a more specific solution for this exact error in Nuxt 4. The problem is most likely related to Docker build configuration or a corrupted project state, rather than a Nuxt or Unhead bug.
If you need more targeted help, please provide your Dockerfile, docker-compose.yaml
, and any custom build steps you are using.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@360783331962650624> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@kapa.ai i have checked everything and with unhead legacy it doesn' tfix my issue
Let me check the knowledge base for you again. One moment! :books:
----------------------
I'm sorry to hear that enabling
If your
If you do not have a proper
Sometimes, subtle configuration or state issues can cause the build to fail to generate the correct output. Users have resolved this by creating a fresh Nuxt project and carefully copying their files over Nuxt3 build .output folder remains empty. If you have already checked these points and the issue persists, the knowledge sources do not provide a more specific solution for this exact error in Nuxt 4. There is no indication that enabling Unhead legacy mode should resolve missing file errors; it is intended for API compatibility only Unhead v2 Upgrade Guide. If you can share your Dockerfile,
unhead.legacy
did not resolve your issue. Based on the knowledge sources, if setting legacy: true
in your nuxt.config
does not fix the missing unhead/dist/server.mjs
error, the problem is likely not related to Unhead's API changes, but rather to your build or deployment setup.
The most common causes for this error, as documented, are:
- Incorrect Docker or deployment configuration:If your
.output
directory is missing files, it may be due to Docker copying or mounting issues. For example, mounting your project directory as a volume in Docker Compose can overwrite the .output
directory generated during build, resulting in missing files at runtime. Removing or adjusting the volume mounts has resolved this for others How to run Nuxt3 with docker (docker compose).
- node_modules copied into the container:If you do not have a proper
.dockerignore
file, your local node_modules
may be copied into the container, causing conflicts and missing modules during build. Adding node_modules
to .dockerignore
and letting the container install dependencies fresh is recommended Docker Build Problem "Error: Cannot find module".
- Corrupted project state:Sometimes, subtle configuration or state issues can cause the build to fail to generate the correct output. Users have resolved this by creating a fresh Nuxt project and carefully copying their files over Nuxt3 build .output folder remains empty. If you have already checked these points and the issue persists, the knowledge sources do not provide a more specific solution for this exact error in Nuxt 4. There is no indication that enabling Unhead legacy mode should resolve missing file errors; it is intended for API compatibility only Unhead v2 Upgrade Guide. If you can share your Dockerfile,
docker-compose.yaml
, and any custom build steps, it may help to further diagnose the issue. Otherwise, the knowledge sources do not contain enough information to provide a definitive fix for your situation.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@360783331962650624> Kapa.ai is still learning and improving, please let me know how I did by reacting below.