H3Error: Cannot find module 'entities/lib/decode.js'
I have a server side nuxt error that starts with
"H3Error: Cannot find module 'entities/lib/decode.js' "
, there is more to it, this isn't the only module that can not be found. I need help understanding why this is and how to resolve this.
This doesn't occur on the local npm run dev or the production build that is run locally. This error only occurs on the server when I run the .output/server/index.mjs file. I use pm2 start to start the server.5 Replies
Hi @Thick Black W. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
The error
Ensure that you run
See example and solution 3. .dockerignore or .gitignore Issues If you use Docker or copy files to the server, ensure that your
See related Docker issue 4. Build/Transpile Configuration If the missing module is a dependency of another package and is not being bundled or transpiled correctly, you may need to add it to the
H3Error: Cannot find module 'entities/lib/decode.js'
occurring only on your server (not locally) when running .output/server/index.mjs
is a common issue in Nuxt deployments and is typically related to missing dependencies or files in your production environment.
Based on the knowledge sources, here are the most likely causes and solutions:
1. Missing Dependencies in Production
When you build your Nuxt app locally, all dependencies are available. However, if you deploy only the .output
directory to your server and do not install production dependencies there, some required modules (like entities
) may be missing. This is especially true if you use a process manager like pm2 and only copy the build output, not the full node_modules
.
Solution:Ensure that you run
npm install
or yarn install
(or your package manager's equivalent) on the server before starting your app with pm2. All dependencies (not just devDependencies) must be present on the server.
2. Incorrect Use of Volumes or Copying in Docker/Deployment
If you use Docker or similar, mounting volumes or copying files incorrectly can result in missing files or folders. For example, mounting your project directory as a volume over the built app can hide the .output
directory or node_modules
in the container, leading to missing modules at runtime.
A similar issue was reported where mounting volumes in Docker Compose caused the .output
folder to be missing, and removing the volumes fixed the problem. Make sure your deployment process does not overwrite or hide the .output
or node_modules
directories on the server.See example and solution 3. .dockerignore or .gitignore Issues If you use Docker or copy files to the server, ensure that your
.dockerignore
or .gitignore
files are not excluding necessary files or folders. Accidentally copying your local node_modules
or missing the install step can cause these errors.See related Docker issue 4. Build/Transpile Configuration If the missing module is a dependency of another package and is not being bundled or transpiled correctly, you may need to add it to the
build.transpile
array in your nuxt.config
:
See troubleshooting ESM issues
---
Summary of steps to resolve:
1. Make sure all dependencies are installed on the server after deployment.
2. Double-check your deployment process (Docker, rsync, etc.) to ensure .output
and node_modules
are present and not overwritten or hidden.
3. If using Docker, avoid mounting volumes that overwrite your build output or dependencies.
4. If the issue persists, try adding the problematic module to build.transpile
in your Nuxt config.
If after these steps the issue remains, try creating a fresh Nuxt project, carefully migrate your files, and see if the problem persists, as sometimes subtle configuration issues can cause build output to be incomplete or incorrect, as noted in another user's experience here.
If you need more specific help, please provide details about your deployment process (Docker, rsync, manual copy, etc.) and your package.json
scripts.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1321238874634195004> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@kapa.ai how do I install all dependencies on the server?
Let me check the knowledge base for you again. One moment! :books:
----------------------
To install all dependencies on the server for your Nuxt application, you should copy your project files (including package.json and lock files) to the server and then run your package manager's install command in the project directory. For example, if you use npm:
Or with yarn:
Or with pnpm:
This will create the node_modules directory with all required dependencies for your application, as described in the Nuxt documentation about the node_modules directory and package.json file. Make sure to do this before running your production build or starting the server process Nuxt node_modules Nuxt package.json.
If you are using Docker, ensure that the install step is included in your Dockerfile before copying the build output or starting the server Docker build example.
If you only copy the .output directory to the server without installing dependencies, required modules will be missing and you will encounter errors like the one you described.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@1321238874634195004> Kapa.ai is still learning and improving, please let me know how I did by reacting below.