安装axios后出现“找不到模块" babel错误 [英] 'Module not found' babel error after installing axios
本文介绍了安装axios后出现“找不到模块" babel错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 create-react-app
设置了一个React项目,然后将 axios
安装在同一项目文件夹中.
I used create-react-app
to set up a React project, then install axios
in the same project folder.
在 App.js
中,我导入并使用了 axios
:
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;
,并出现以下错误:
./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?
推荐答案
确保您具有npm的最新版本.
Make sure you have the latest version of npm.
npm install npm@latest -g
如果仍然不起作用,您可以尝试删除node_modules并再次运行npm install
If that still doesn't work you could try removing node_modules and running npm install again
rm -Rf node_modules
npm install
这篇关于安装axios后出现“找不到模块" babel错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文