Skip to content
Node.js and Python3 min read

Node.js Error: Cannot find module

Error: Cannot find module 'express'

Short answer

Error: Cannot find module means Node.js looked for a package or file your code imports and didn't find it. For a package name such as 'express', the dependencies aren't installed where the app runs, so run `npm install` or `npm ci`; for a path such as './utils', the file name, case or extension is wrong.

ArabyHost teamLast updated: ShareWhatsAppXLinkedIn
Contents
  1. What the variants mean
  2. Causes
  3. How to fix it
  4. Prevention
  5. On ArabyHost

Node.js resolves every require() and import by searching node_modules folders (for package names) or the exact path you wrote (for anything starting with ./, ../ or /). The error shows what it looked for, and the Require stack below it shows which of your files asked. That tells you whether the problem is a missing install or a wrong path.

What the variants mean

Message Usual cause
Cannot find module 'express' The package isn’t installed where the app runs
Cannot find module './config' Wrong relative path, name or letter case
Cannot find module '/home/user/app/dist/index.js' Wrong startup file, or the build was never run
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'express' imported from ... Same as the first row, in an ES module project
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '.../utils' imported from ... ES modules need the full file name: ./utils.js

Causes

  • The project was cloned or uploaded without node_modules, and nobody ran an install on the server.
  • The package was never added to package.json (installed globally, or in another folder).
  • A package listed in devDependencies is needed at runtime, but production installs skip dev packages.
  • Letter case differs between the import and the file name.
  • The startup file points to a build folder (dist/, build/) that doesn’t exist yet.
  • The install was run in a different directory from the one the app runs in.

How to fix it

  1. Read the name in quotes. A bare name is a package; a name starting with . or / is a file path.

  2. For a package, install dependencies in the folder that contains package.json:

    npm ci          # exact versions from package-lock.json
    npm install     # if there's no lock file
  3. Check that the package is declared. npm ls express shows whether it’s installed; if it isn’t in package.json, add it with npm install express.

  4. Move runtime packages out of devDependencies. If the app needs it in production, it belongs in dependencies.

  5. Do a clean reinstall when the folder is half-installed: rm -rf node_modules && npm ci.

  6. For a path, compare it with the real file: ls -l src/ shows exact names and case. In ES modules, add the extension (./utils.js).

  7. For a missing build file, run the build first (npm run build) and confirm the startup file path.

  8. Restart the app and watch the log for the next error, if any.

If installs fail with a dependency conflict, see npm ERR! ERESOLVE.

Prevention

  • Commit package-lock.json and use npm ci in every deploy.
  • Keep node_modules in .gitignore and install on the target server.
  • Use consistent lowercase file names.
  • Test a fresh clone in an empty folder before deploying.

On ArabyHost

On AI/Developer plans, Node.js apps run through cPanel’s Setup Node.js App (CloudLinux selector with Phusion Passenger), which creates a separate environment for the app’s packages. The Run NPM Install button installs everything in package.json into that environment. The node_modules entry in the app folder is a link the selector manages, so don’t upload your own node_modules folder; the selector refuses to work with one. Over SSH, copy the command shown at the top of the app’s page to enter its environment, then run npm ci. When you deploy from GitHub with .cpanel.yml, run the install after each deploy; see Git deployment in cPanel and the Node.js deployment guide.

FAQ

Should I upload node_modules to the server?

Usually not. Upload `package.json` and `package-lock.json`, then install on the server, so native modules are built for its system. Uploading node_modules is slow and can break packages compiled for your own OS.

Do I need to delete package-lock.json to fix it?

Rarely. Deleting node_modules and running `npm ci` is enough in most cases. Deleting the lock file lets npm pick newer versions, which can introduce other errors.

Why does it work on Windows but not on the Linux server?

Windows and macOS ignore letter case in file names by default; Linux doesn't. `require('./Utils')` finds `utils.js` on your laptop but fails on the server.

Useful? Share it with someone who needs it:WhatsAppXLinkedIn

Read next

Ready to put your idea online?

Fast, isolated hosting, support that understands you, and an AI assistant that fixes problems with you.