Katie
Katie

Reputation: 1031

'Module not found' babel error after installing axios

I used create-react-app to set up a React project, then install axios in the same project folder.

In App.js, I imported and used axios:

import React, { Component } from 'react';
import './App.css';
import axios from 'axios';

class App extends Component {
  state = {users: []}

  componentDidMount() {
    axios.get('/users')
      .then(res => res.json())
      .then(users => this.setState({ users }));
  }

  render() {
    return (
      <div className="App">
        <h1>Users</h1>
        {this.state.users.map(user =>
          <div key={user.id}>{user.username}</div>
        )}
      </div>
    );
  }
}

export default App;

and got the following error:

./node_modules/axios/index.js
Module not found: Can't resolve '/Users/katietruong/Projects/read- 
it/client/node_modules/react-scripts/node_modules/babel- 
loader/lib/index.js' in '/Users/katietruong/Projects/read-it/client' 
.  

How does it happen and how can I fix it?

Upvotes: 0

Views: 1251

Answers (1)

varoons
varoons

Reputation: 3887

Make sure you have the latest version of npm.

npm install npm@latest -g

If that still doesn't work you could try removing node_modules and running npm install again

rm -Rf node_modules
npm install

Upvotes: 1

Related Questions