Closed cittadhammo closed 2 years ago
Exactly the same issue here with node v16.14.0
Hi @cittadhammo, thanks for creating this issue.
I was able to reproduce the error. I believe it is because the file main.js
is executed in the browser. The deepl-node
library is intended to be run by Node on the server, not in the browser. It might be possible with vite to execute functions on the server-side, but I am not familiar enough with vite to say how.
OK thank you.
I've used this code finally that works in the browser :
const urlDeepL = 'https://api-free.deepl.com/v2/translate?auth_key='+authKey+'&text='+sentence+'&target_lang='+targetLanguage+'&preserve_formatting=1';
const responseDeepL = await fetch(urlDeepL);
const dataDeepL = await responseDeepL.json();
const text = dataDeepL.translations[0].text
Hi @cittadhammo, great that you found a solution to your problem.
I want to warn you that with this approach your auth key is exposed in the browser: anyone accessing the page can see your key. So you should not share this page with anyone you do not trust, for example it should not be hosted on the internet.
Yes I was planning to request a key input from user before using the app on the internet.
Thanks for your help and be well ;-)
Hi,
I'm trying to build a node app with vite using :
npm create vite@latest
when using your code example after installing
npm install deepl-node
:I get the following error:
I have a free account with DeepL
Thanks! (I'm pretty new to this ;-)