Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find module axios - compatibility issue with typescript

I installed Axios local to my Typescript project, but generate an error when trying to import it. Error: "Cannot Find module axios".

root folder

npm install --save-dev axios

src/app.ts

import axios from 'axios';

package.json

 "devDependencies": {
    "axios": "^0.21.1",

It has something to do with my tsconfig.json. If I remove this file, axios is known. If I restore this file, the error comes back in VS Code. I know for Lodash package there is a Lodash types (https://www.npmjs.com/package/@types/lodash) to make lodash compatible with typescript. Is there an equivelent for axios?

I have this file .\node_modules\axios\index.d.ts that is supposed to help me out with typescript compatibility. Somehow it's not working.

like image 660
Bill Avatar asked Oct 26 '25 06:10

Bill


1 Answers

This seems to help. It lets TS understand Axios. Even though Axios was supposed to work out of the box.

npm install --save @types/axios
like image 164
Bill Avatar answered Oct 28 '25 21:10

Bill



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!