Last modified: Jun 24, 2025 By Alexander Williams
Fix Error: Cannot find module 'eslint'
If you see the error Cannot find module 'eslint', don't worry. This is a common issue in Node.js projects. It happens when ESLint is not installed correctly.
Table Of Contents
What Causes This Error?
The error occurs when Node.js cannot locate the ESLint module. This usually happens for one of these reasons:
- ESLint is not installed in your project.
- ESLint is installed globally but not locally.
- The module path is incorrect.
- Node.js cannot access the module due to permission issues.
Similar errors can occur with other modules like nodemon or express.
How to Fix the Error
1. Install ESLint Locally
The best practice is to install ESLint as a dev dependency in your project. Run this command in your project root:
npm install eslint --save-dev
This installs ESLint in your node_modules
folder and adds it to package.json
.
2. Check Global Installation
If you prefer global installation, ensure ESLint is installed globally:
npm install -g eslint
Then verify the installation:
eslint --version
3. Verify Node.js Path
Sometimes, Node.js cannot find modules due to path issues. Check your NODE_PATH
environment variable:
echo $NODE_PATH
If it's empty, you might need to set it. This issue can also affect other modules like dotenv.
4. Reinstall Node Modules
Corrupted node_modules
can cause this error. Delete the folder and reinstall:
rm -rf node_modules
npm install
5. Check File Permissions
Permission issues can prevent Node.js from accessing modules. Fix permissions with:
sudo chown -R $(whoami) ~/.npm
sudo chown -R $(whoami) node_modules
Example Project Setup
Here's how a proper ESLint setup should look:
# Initialize a new project
mkdir my-project
cd my-project
npm init -y
# Install ESLint
npm install eslint --save-dev
# Initialize ESLint config
npx eslint --init
The npx eslint --init
command helps you create a configuration file.
Common Mistakes to Avoid
Avoid these mistakes when working with ESLint:
- Forgetting to install ESLint before running it
- Mixing global and local installations
- Not having proper configuration files
These same principles apply to other modules like any Node.js module.
Conclusion
The Cannot find module 'eslint' error is easy to fix. Most times, installing ESLint locally solves it. Always ensure your project dependencies are properly installed.
Remember to check your installation, paths, and permissions. With these steps, you should be able to resolve the error quickly.