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
devDependenciesis 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
-
Read the name in quotes. A bare name is a package; a name starting with
.or/is a file path. -
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 -
Check that the package is declared.
npm ls expressshows whether it’s installed; if it isn’t inpackage.json, add it withnpm install express. -
Move runtime packages out of devDependencies. If the app needs it in production, it belongs in
dependencies. -
Do a clean reinstall when the folder is half-installed:
rm -rf node_modules && npm ci. -
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). -
For a missing build file, run the build first (
npm run build) and confirm the startup file path. -
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.jsonand usenpm ciin every deploy. - Keep
node_modulesin.gitignoreand 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.