Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module '"axios"' has no exported member 'AxiosError'.ts(2305) #6527

Open
BarishSarac opened this issue Aug 5, 2024 · 7 comments
Open

Module '"axios"' has no exported member 'AxiosError'.ts(2305) #6527

BarishSarac opened this issue Aug 5, 2024 · 7 comments

Comments

@BarishSarac
Copy link

Describe the issue

Hi,

I have nextjs typescript app and I am using AxiosError like onError?.(error as AxiosError); and I get Module '"axios"' has no exported member 'AxiosError'.ts(2305) error. I installed types doing npm install axios @types/axios still same issue, also they are imported import axios, { AxiosError } from "axios";. How can I fix this?

Example Code

import axios, { AxiosError } from 'axios';

interface ApiResponse {
  id: number;
  name: string;
}

const fetchData = async () => {
  try {
    const response = await axios.get<ApiResponse>('http://localhost:8080/api/data');
    console.log('Data:', response.data);
  } catch (error) {
    if (axios.isAxiosError(error)) {
      console.error('Axios error:', error.message);
    } else {
      console.error('Unexpected error:', error);
    }
  }
};

fetchData();

Expected behavior

AxiosError not to show error in typescript
Module '"axios"' has no exported member 'AxiosError'.ts(2305)

Axios Version

1.7.3

Adapter Version

No response

Browser

Chrome

Browser Version

127

Node.js Version

20.15.1

OS

No response

Additional Library Versions

No response

Additional context/Screenshots

No response

@Anonymous961
Copy link

@BarishSarac, try removing the node_modules folder and reinstalling all the dependencies. I'm not facing this issue. Also, I don't think there is a need to install @types/axios. If you're still facing this issue, then try removing the node_modules folder, remove axios from package.json, and then reinstall axios.

@BarishSarac
Copy link
Author

Hello @Anonymous961,

I created a new nextjs app to test from scratch. So I used npx create-next-app and then installed axios but I still get the error. I activated typescript, so I tested even with @types/axios installed, still getting error. So fresh nextjs app, having axios installed still giving this error.

image

@Jey-Alt
Copy link

Jey-Alt commented Aug 11, 2024

@BarishSarac, try removing the node_modules folder and reinstalling all the dependencies. I'm not facing this issue. Also, I don't think there is a need to install @types/axios. If you're still facing this issue, then try removing the node_modules folder, remove axios from package.json, and then reinstall axios.

I had the same issue, this fixed it for me

@BarishSarac try using a venv maybe?

@BarishSarac
Copy link
Author

BarishSarac commented Aug 11, 2024

@BarishSarac, try removing the node_modules folder and reinstalling all the dependencies. I'm not facing this issue. Also, I don't think there is a need to install @types/axios. If you're still facing this issue, then try removing the node_modules folder, remove axios from package.json, and then reinstall axios.

I had the same issue, this fixed it for me

@BarishSarac try using a venv maybe?

@Jey-Alt, thank you for recommendation

It worked when I upgraded packages, deleted node_modules and installed it back

@RakibulMRH
Copy link

{
"compilerOptions": {
// ... other options ...
"typeRoots": ["./node_modules/@types"],
"types": ["offscreencanvas", "stats.js", "webxr"]
},
"include": ["next-env.d.ts", "/*.ts", "/*.tsx"],
"exclude": ["node_modules"]
}

updating tsconfig.json fixed the issue for me

@manuman94
Copy link

In my case it was that I installed @types/axios by error. The package is unmantained, so don't use it.

Removing it from package.json and "npm i" did the trick

@cloudfocus
Copy link

@manuman94 or uninstall the package: npm uninstall @types/axios

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants