DeepLcom / deepl-node

Official Node.js library for the DeepL language translation API.
MIT License
370 stars 22 forks source link

Uncaught TypeError: os.type is not a function #31

Closed alandolsi closed 1 year ago

alandolsi commented 1 year ago

I become this error when i initialise the repository

Uncaught TypeError: os.type is not a function at Translator.constructUserAgentString (deepl-node.js?v=e2e7fb1a:3446:33) at new Translator (deepl-node.js?v=e2e7fb1a:3116:30) at main.js:8:20 constructUserAgentString @ deepl-node.js?v=e2e7fb1a:3446 Translator @ deepl-node.js?v=e2e7fb1a:3116 (anonym) @ main.js:8

JanEbbing commented 1 year ago

Hi, which version of NodeJS are you using? Are you using some kind of framework to build an application with (React Native, Ionic, etc)? It seems the os module of Node isn't available.

I will create a task anyway to make sure an exception in that function doesn't break the library.

alandolsi commented 1 year ago

Hi,

I test it with node v18.16.1 (npm v9.5.1) and with node v16.20.0 (npm v8.19.4) I am using vitejs.

thank you

JanEbbing commented 1 year ago

Thanks, I can reproduce this and will look into it.

JanEbbing commented 1 year ago

Hi @alandolsi .

  1. To fix the direct error you are seeing, you need to polyfill the os module as Vite does not. There are some people with similar problems and their solutions here, here and this is a module which does this.
  2. However, this is a NodeJS package and the above is a bandaid solution. Please read this answer why we don't support running in the frontend (I think this is the next problem you would run into, aside from likely leaking your API key in the frontend source code). You will need some backend that can make the DeepL API requests.

Please let me know if this doesn't solve your problem.

alandolsi commented 1 year ago

@JanEbbing Thank you for help.