How to fix Error: Cannot find module './lib/helper' from '/home/app.js' in Node.js

Node.jsINTERMEDIATEMEDIUMUpdated Dec 9, 2025· 173 views

This error occurs when Node.js cannot locate a module specified in a require() or import statement. Common causes include typos in the file path, missing files, incorrect relative paths, or uninstalled dependencies. The error typically happens with local file imports that point to non-existent paths or third-party packages that haven't been installed.

Quick fix

Fixes Error: Cannot find module './lib/helper' from '/home/app.js'

# Check if the file exists from your project root
ls -la lib/helper.js

# Or if it's in a subdirectory
ls -la src/lib/helper.js

# If it's a directory with index.js
ls -la lib/helper/index.js
  1. Verify the file exists at the specified path
  2. Check for typos and case sensitivity
  3. Fix relative paths in require statements
  4. Handle file extensions correctly
node.js — error
# Check if the file exists from your project root
ls -la lib/helper.js
# Or if it's in a subdirectory
ls -la src/lib/helper.js
# If it's a directory with index.js
ls -la lib/helper/index.js
Error: Cannot find module './lib/helper' from '/home/app.js'

What this error means

When you use require() or import in Node.js, it searches for the specified module following a specific resolution order: built-in core modules (like 'fs', 'path'), npm packages in node_modules, and finally relative or absolute file paths. This error indicates that the module cannot be found in any of these locations. The error message shows the module name you tried to require and the file that contains the require statement, helping you identify the problem. This is typically a file system issue—the file doesn't exist, the path is wrong, or the file was deleted.

Typical symptoms

  • Application fails to start with 'Cannot find module' errors
  • Specific require or import statements throw module resolution errors
  • Error message includes the module path you tried to load and the requiring file's location
  • Code works in one environment but fails in another (e.g., locally vs production)
  • Error appears after renaming files, directories, or reorganizing the project structure

Common causes

  1. The required file does not exist at the specified path (most common cause)
  2. Typo or incorrect spelling in the module path or filename
  3. Incorrect relative path that points to the wrong directory level
  4. Case sensitivity mismatch on case-sensitive filesystems (Linux, macOS)
  5. Missing or uninstalled npm dependency
  6. Module path doesn't include the file extension when Node.js expects it
  7. Circular dependency between modules
  8. Stale or corrupt node_modules directory from failed installations

How to fix "Error: Cannot find module './lib/helper' from '/home/app.js'"

1Verify the file exists at the specified path

First, confirm that the file you're trying to require actually exists at the location specified:

bash
# Check if the file exists from your project root
ls -la lib/helper.js

# Or if it's in a subdirectory
ls -la src/lib/helper.js

# If it's a directory with index.js
ls -la lib/helper/index.js

If the file doesn't exist, you need to either create it or adjust your require path to point to the correct file. If you recently deleted a file and this error started appearing, consider restoring it from version control using git checkout.

2Check for typos and case sensitivity

Carefully review the require statement for any spelling mistakes:

javascript
// Bad - typo in filename
const helper = require('./lib/halper');  // typo: halper instead of helper

// Good - correct filename
const helper = require('./lib/helper');

On Linux and macOS, filenames are case-sensitive, so these are treated as different files:

bash
# These are DIFFERENT files on Linux/macOS
Helper.js    # capital H
helper.js    # lowercase h

On Windows, filenames are case-insensitive, so both would work—but if you move code to Linux/macOS, it will break. Ensure your require statement matches the actual filename's case exactly.

3Fix relative paths in require statements

Verify that your relative path is correct based on where the requiring file is located:

bash
Project structure:
app.js
lib/
  helper.js

// In app.js - correct relative path
const helper = require('./lib/helper');

If your file structure is different, adjust the path accordingly:

bash
Project structure:
src/
  app.js
  lib/
    helper.js

// In src/app.js
const helper = require('./lib/helper');

// If helper.js is in a different location
src/
  app.js
  utils/
    helper.js

// In src/app.js, use proper relative path
const helper = require('./utils/helper');

// To go up one directory level and back down
src/
  config/
    app.js
  lib/
    helper.js

// In src/config/app.js, go up with ../
const helper = require('../lib/helper');
4Handle file extensions correctly

Node.js automatically resolves certain file extensions for CommonJS. When you require a file without specifying an extension, Node.js tries these in order:

javascript
const helper = require('./lib/helper');
// Node.js tries in this order:
// 1. ./lib/helper (as a directory with index.js)
// 2. ./lib/helper.js
// 3. ./lib/helper.json
// 4. ./lib/helper/index.js

If your file is named helper.js, you can require it as require('./lib/helper') without the extension. Node.js will find it. But if none of these forms exist, the error occurs.

For ES modules (import/export), you MUST include the file extension:

javascript
// CommonJS (no extension needed)
const helper = require('./lib/helper');

// ES modules (extension required)
import helper from './lib/helper.js';
5Check for missing npm dependencies

If you're trying to require a third-party package (not a local file), ensure it's installed:

bash
# Check if the package is listed in package.json
grep 'package-name' package.json

# Install the missing package
npm install package-name

# If the package is in package.json but not installed
npm install

# Verify it was installed
ls node_modules/package-name

Example for a specific package:

bash
# Install lodash if missing
npm install lodash

# Then require it
const _ = require('lodash');
6Reinstall dependencies if errors persist

If you've verified all paths and files exist but the error continues, your node_modules directory may be corrupted or outdated:

bash
# Remove the corrupted node_modules and lock file
rm -rf node_modules package-lock.json

# Reinstall all dependencies from package.json
npm install

# If npm cache is corrupted, clear it
npm cache clean --force

# Then try your code again
node app.js

This ensures all dependencies are fresh, properly installed, and their versions match your package.json.

Advanced notes

To debug module resolution issues, Node.js provides the require.resolve() function that shows what path Node.js actually resolves:

javascript
try {
  const resolvedPath = require.resolve('./lib/helper');
  console.log('Module found at:', resolvedPath);
} catch (e) {
  console.log('Module resolution failed:', e.message);
}

You can also enable detailed module resolution logging:

bash
NODE_DEBUG=module node app.js

This prints extensive information about where Node.js searches for modules, helping you understand the resolution process.

For complex projects with many interdependencies, consider using a bundler like webpack, esbuild, or Parcel that can pre-bundle all dependencies and provide better error messages. Bundlers can also help catch module resolution issues at build time rather than runtime.

Circular dependencies can also cause module resolution failures. If module A requires B and module B requires A, you may see this error or related initialization errors. Break circular dependencies by:
1. Restructuring your code to eliminate the dependency cycle
2. Moving shared code to a third module that both depend on
3. Using lazy require (requiring inside a function rather than at module scope)

For ES modules, the module resolution is stricter than CommonJS. All relative paths must start with './', '../', or '/', and file extensions are mandatory. This provides better static analysis and tooling support but requires more explicit path specifications.

Frequently asked questions

What does "Error: Cannot find module './lib/helper' from '/home/app.js'" mean?
js, it searches for the specified module following a specific resolution order: built-in core modules (like 'fs', 'path'), npm packages in node_modules, and finally relative or absolute file paths. This error indicates that the module cannot be found in any of these locations. The error message shows the module name you tried to require and the file that contains the require statement, helping you identify the problem.
How do I fix "Error: Cannot find module './lib/helper' from '/home/app.js'"?
This error occurs when Node.js cannot locate a module specified in a require() or import statement. Common causes include typos in the file path, missing files, incorrect relative paths, or uninstalled dependencies. The error typically happens with local file imports that point to non-existent paths or third-party packages that haven't been installed.
What causes "Error: Cannot find module './lib/helper' from '/home/app.js'"?
The required file does not exist at the specified path (most common cause) Typo or incorrect spelling in the module path or filename Incorrect relative path that points to the wrong directory level
Is the "Error: Cannot find module './lib/helper' from '/home/app.js'" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading