dveldhoen / easyinvoice

MIT License
162 stars 30 forks source link

easyinvoice.js:29 Uncaught (in promise) TypeError: axios_1.default.create is not a function #85

Closed LouisMuriuki closed 1 year ago

LouisMuriuki commented 1 year ago

i am using it in react as follows

import easyinvoice from "easyinvoice";

const DownloadInvoice = (data:any) => { easyinvoice.createInvoice(data, function (result: { pdf: string | undefined; }) { easyinvoice.download("Invoice.pdf", result.pdf); }); };

but when i try to download i get the error easyinvoice.js:29 Uncaught (in promise) TypeError: axios_1.default.create is not a function

MitkoAntov commented 1 year ago

Try the async/await way, I don't have any problems. Also check if you have installed the latest version of the package

dveldhoen commented 1 year ago

I just tried it using promises, without async/await. Also works fine:

easyinvoice.createInvoice({}).then((result)=>{
   easyinvoice.download("test.pdf", result.pdf); 
});
LouisMuriuki commented 1 year ago

@dveldhoen I still get the error, iam on the latest version 3.0.10, is there any extra step? I import from react then create and download the invoice as shown on my code above. The data object is as same as you have provided in the example

dveldhoen commented 1 year ago

Don't use your own code. It probably has bugs. Use on of ours.

dveldhoen commented 1 year ago

Or start from on of our samples in the documentation.

LouisMuriuki commented 1 year ago

easyinvoice.createInvoice({}).then((result) => { easyinvoice.download("test.pdf", result.pdf); }); This exactly what my code looks like ,its in a parent functions that runs onClick, iam certain this is what the documentation looks like,did i miss something?

dveldhoen commented 1 year ago

In React, did you import it? import easyinvoice from 'easyinvoice'

LouisMuriuki commented 1 year ago

yes i did

dveldhoen commented 1 year ago

Are you using an old Axios version perhaps? Can you try updating that?

LouisMuriuki commented 1 year ago

Let me try that,

LouisMuriuki commented 1 year ago

issue persists, in my project i have to use --legacy-peer-deps while adding some other dependancies, might that be an issue?

dveldhoen commented 1 year ago

Could be, it's never recommended anyway to use that prop. Better to resolve the actual issues. I'm looking if I can easily replace axios with the native fetch api. This will probably also fix your issue and make the package smaller as well.

LouisMuriuki commented 1 year ago

okay, that would be great, i find the package perfectly suitable for my project

dveldhoen commented 1 year ago

I just looked into it, but it has more implications than I thought since only the latest Node versions support the fetch api. And I have to consider compatibility, with both browsers and earlier node versions. I think you are better off fixing your legacy peer deps issues.

dveldhoen commented 1 year ago

Probably if you lookup axios in your node_modules it will show you a version below v1. Which is probably not compatible. We use axios@^1

dveldhoen commented 1 year ago

And this conflict is caused by legacy-peer-deps. Since it will ignore package dependencies just to solve some errors.

LouisMuriuki commented 1 year ago

in my node_modules/axios/package.json it shows version as 1.3.4

dveldhoen commented 1 year ago

After a quick Google, I found this: https://github.com/facebook/create-react-app/issues/11889

There could be an issue with .cjs files not being compiled like they should. Perhaps this helps you out.

LouisMuriuki commented 1 year ago

Okay thanks, let me try it it with craco and see

dveldhoen commented 1 year ago

By the way, downgrading to easyinvoice@^2 will use an older axios version. Which could also solve your issue. Though the api v2 is calling will be deprecated next year. So I don't recommend using older versions.

LouisMuriuki commented 1 year ago

The cjs file was not being compiled properly hence the issue, patching it with craco made it work and i can now download the pdf file as intended. Your help is very much appreciated @dveldhoen

dveldhoen commented 1 year ago

That's great. Good to hear.

dveldhoen commented 1 year ago

We lowered the Axios version in our version 3.0.12. It will then work without the Craco workaround. Thought you might be interested. We did this since more people ran into the problem.

LouisMuriuki commented 1 year ago

okay, I will test it out and get back to you