Closed LouisMuriuki closed 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
I just tried it using promises, without async/await. Also works fine:
easyinvoice.createInvoice({}).then((result)=>{
easyinvoice.download("test.pdf", result.pdf);
});
@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
Don't use your own code. It probably has bugs. Use on of ours.
Or start from on of our samples in the documentation.
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?
In React, did you import it?
import easyinvoice from 'easyinvoice'
yes i did
Are you using an old Axios version perhaps? Can you try updating that?
Let me try that,
issue persists, in my project i have to use --legacy-peer-deps while adding some other dependancies, might that be an issue?
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.
okay, that would be great, i find the package perfectly suitable for my project
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.
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
And this conflict is caused by legacy-peer-deps. Since it will ignore package dependencies just to solve some errors.
in my node_modules/axios/package.json it shows version as 1.3.4
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.
Okay thanks, let me try it it with craco and see
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.
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
That's great. Good to hear.
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.
okay, I will test it out and get back to you
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