Last modified: Jun 24, 2025 By Alexander Williams

Fix Error: Cannot find module 'axios'

Node.js developers often face the error Error: Cannot find module 'axios'. This happens when the Axios library is missing or not installed correctly.

This guide explains how to fix it quickly.

Why the error occurs

The error appears when Node.js cannot locate the Axios package. Common causes include:

  • Axios not installed in your project
  • Incorrect installation
  • Node_modules folder issues
  • Path resolution problems

Solution 1: Install Axios

The simplest fix is to install Axios using npm or yarn. Run this command in your project directory:


npm install axios

Or if using yarn:


yarn add axios

Solution 2: Check package.json

Verify Axios appears in your package.json dependencies. If missing, install it again.


{
  "dependencies": {
    "axios": "^1.6.2"
  }
}

Solution 3: Reinstall node_modules

Sometimes the node_modules folder gets corrupted. Delete it and reinstall:


rm -rf node_modules
npm install

Solution 4: Global vs local installation

Ensure Axios is installed locally, not globally. Global packages can cause module resolution issues.

Solution 5: Verify import statement

Check your import statement matches this format:


const axios = require('axios'); // CommonJS
// or
import axios from 'axios'; // ES Modules

Solution 6: Clear npm cache

A corrupted npm cache can cause installation problems. Clear it with:


npm cache clean --force

Solution 7: Check Node.js version

Older Node.js versions might have compatibility issues. Update to the latest LTS version.

Example: Using Axios correctly

Here's a working example after proper installation:


const axios = require('axios');

axios.get('https://api.example.com/data')
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.error('Error:', error);
  });

Common mistakes

Avoid these mistakes that trigger the error:

  • Typo in 'axios' (like 'axio' or 'axois')
  • Installing in wrong directory
  • Using wrong package manager

For similar issues with other modules, see our guide on fixing Express module errors.

Conclusion

The Cannot find module 'axios' error is easy to fix. Most cases resolve by installing Axios properly. Always check your package.json and node_modules.

Follow these steps to get your HTTP requests working with Axios again.