infinitered / apisauce

Axios + standardized errors + request/response transforms.
MIT License
2.78k stars 184 forks source link

TypeError: axios.create is not a function error #316

Open akshaymohana-btc opened 1 year ago

akshaymohana-btc commented 1 year ago

After upgrading apisauce to latest(3.0.1) version I got TypeError: axios.create is not a function error.

Issue: Apisauce was failing to create ApisauceInstance using create function. Fix: After downgrading apisauce to 3.0.0 version works in normal way.

JohnieXu commented 1 year ago

I also encountered the same error and found that axios is a string after troubleshooting.

image

webpack 5.88 apisauce 3.0.1 node.js 16.13

image image

After webpack bundling, the axios is compiled into:

image

I suspect it could be an issue with how webpack handles dependencies or there might be an issue with the exports in the axios package's configuration file.

image
Taelar commented 1 year ago

Same problem here while upgrading from 2.0 to 3.0.1 on a Create React App project (webpack). It seems to be a problem with a certain version of axios that does not export properly the create() function, see axios/axios#5613 and axios/axios#5038. I'm very interested in any workaround. 🙏

JohnieXu commented 1 year ago

The apisauce@3.0.1 udpdate axios to ^1.4.0 caused this problem, It appears to be a problem with create-react-app, as described in this GitHub issue: https://github.com/facebook/create-react-app/issues/11889.

Since the issue is still open, some fixed pull requests have been submitted, but create-react-app (cra) has not yet adopted them.

It may be necessary to revert to apisauce@3.0.0 until the aforementioned GitHub issue is resolved. In apisauce@3.0.0, axios@0.27.2 is used, which does not have this problem.