Module not found: Can't resolve 'axios' in ReactJs
I'm a newbie in ReactJs. and I use axios
plugin to help call and get data from an API.
I try to import that plugin in my LoginService.ts
as below:
import axios, { AxiosResponse, AxiosInstance } from 'axios';
But when run app I got an error Module not found: Can't resolve 'axios' in 'C:\dev\first-project\node_modules\axios'
ERROR in ./~/axios/index.js
Module not found: Error: Can't resolve './lib/axios' in 'C:\dev\first-project\node_modules\axios'
resolve './lib/axios' in 'C:\dev\first-project\node_modules\axios'
using description file: C:\dev\first-project\node_modules\axios\package.json (relative path: .)
after using description file: C:\dev\first-project\node_modules\axios\package.json (relative path: .)
using description file: C:\dev\first-project\node_modules\axios\package.json (relative path: ./lib/axios)
as directory
C:\dev\first-project\node_modules\axios\lib\axios doesn't exist
no extension
C:\dev\first-project\node_modules\axios\lib\axios doesn't exist
.ts
C:\dev\first-project\node_modules\axios\lib\axios.ts doesn't exist
[C:\dev\first-project\node_modules\axios\lib\axios]
[C:\dev\first-project\node_modules\axios\lib\axios]
[C:\dev\first-project\node_modules\axios\lib\axios.ts]
@ ./~/axios/index.js 1:17-39
@ ./src/services/GroupService.ts
@ ./src/first-project.ts
It's still working fine for me, but after I get code from GitLab and this error occurs.
How can I resolve it?
-
T4
Thắng Ngô Minh Jun 19 2021
If before that it still working fine. I think you need to update your npm to try update all package.
npm install -- OR npm update
I hope it work for you.
-
G1
Gornpol Suksumrate Jun 19 2021
Looks like axios isn't installed. Try
npm install --save axio
s. Then double check your import statement. It should beimport axios from 'axios'
This solved the problem.
-
M-1
Mukesh kumar Jun 19 2021
You probably need to re-install that dependency to your project in order to make it work.
Run
npm install axios
oryarn add axios
depending if you are using npm/yarn -
D-2
Developer Jun 19 2021
Webpack can not find an entry point for
axios
, because try to search typescript file, but there is no such file. You should add.js
to the resolve extensions. Open webpack.config.js file and change as below:resolve: { extensions: ['.ts', '.js'] },
I hope it works for you!
* Type maximum 2000 characters.
* All comments have to wait approved before display.
* Please polite comment and respect questions and answers of others.