axios / axios

Promise based HTTP client for the browser and node.js
https://axios-http.com
MIT License
105.72k stars 10.96k forks source link

axios v1.2.2 AxiosInstance import error with Vite #5432

Open nicolasassi opened 1 year ago

nicolasassi commented 1 year ago

Describe the bug

In Vue3 / TypeScript project, import { AxiosError } from 'axios';

Build shows warning: Non-existent export 'AxiosError' is imported from node_modules/axios/index.js

Although there is only a build warning, any component (Vue) or TypeScript (ts) that includes this import fails to work. Browser console (Dev-Tools) shows:

Uncaught SyntaxError: The requested module '/node_modules/.vite/deps/axios.js?v=bd690d6d' does not provide an export named 'AxiosInstance'

To Reproduce

No response

Code snippet

No response

Expected behavior

Should not break

Axios Version

1.2.2

Adapter Version

No response

Browser

Chrome

Browser Version

No response

Node.js Version

v18.9.0

OS

macOs 12.6.2

Additional Library Versions

Vue3 / TypeScript

Additional context/Screenshots

No response

Spaceman2019 commented 1 year ago

I have the same problem with Svelte: Uncaught (in promise) SyntaxError: The requested module '/node_modules/.vite/deps/axios.js?v=db70df63' does not provide an export named 'AxiosInstance'

lzhgostudy commented 1 year ago

you can try that import type { AxiosInstance } from "axios";

papiguy commented 1 year ago

I am getting this issue Missing "./index" specifier in "axios" package when I have the above suggestion

AmirHo3sein commented 6 months ago

I have the same problem with vue 3 and vite 5: Uncaught (in promise) SyntaxError: The requested module '/node_modules/.vite/deps/axios.js?v=db70df63' does not provide an export named 'axios'

marvellusintech commented 6 months ago

Hey guys, has any one found the solution to this yet?

GoodGuyGregory commented 5 months ago

any solutions or updates on this?

ggascoigne commented 4 months ago

based on another issue (that I can't find right now), I have to patch axios when using vite.

My patch looks like this:

diff --git a/package.json b/package.json
index 860d614056358d73a0525022bfe41b2aaa0d9b7e..c019f57adbabe20701c2232d1b6509bed72c212c 100644
--- a/package.json
+++ b/package.json
@@ -11,7 +11,7 @@
       },
       "browser": {
         "require": "./dist/browser/axios.cjs",
-        "default": "./index.js"
+        "default": "./dist/esm/axios.js"
       },
       "default": {
         "require": "./dist/node/axios.cjs",

Hope that helps.