Reputation: 753
I am trying to use deepl-node package https://www.npmjs.com/package/deepl-node on a Vue 3 app running on vite 5.0.11.
I am just using the example usage from the docs, but the app throws the following error
import * as deepl from 'deepl-node';
const authKey = "---"; // Replace with your key
const translator = new deepl.Translator(authKey);
(async () => {
const result = await translator.translateText('Hello, world!', null, 'fr');
console.log(result.text); // Bonjour, le monde !
})();
deepl-node.js?v=2f8c41fd:2475 Uncaught TypeError: http.Agent is not a constructor
at node_modules/deepl-node/dist/client.js (deepl-node.js?v=2f8c41fd:2475:18)
at __require (chunk-P2LSHJDD.js?v=45007535:4:50)
at node_modules/deepl-node/dist/index.js (deepl-node.js?v=2f8c41fd:3021:20)
at __require (chunk-P2LSHJDD.js?v=45007535:4:50)
at deepl-node.js?v=2f8c41fd:3566:16
node_modules/deepl-node/dist/client.js @ deepl-node.js?v=2f8c41fd:2475
__require @ chunk-P2LSHJDD.js?v=45007535:4
node_modules/deepl-node/dist/index.js @ deepl-node.js?v=2f8c41fd:3021
__require @ chunk-P2LSHJDD.js?v=45007535:4
(anonymous) @ deepl-node.js?v=2f8c41fd:3566
Show 5 more frames
Show less
Upvotes: 0
Views: 550
Reputation: 410
This specific error is caused by vite not polyfilling the http
module, see similar questions.
More generally, what you are trying to do likely does not work - the deepl-node
library will only work on a full NodeJS
backend, it is not designed for a frontend app (as you would leak your key in the source code which would be accessible to users). You need to put the translation code in some backend and add a call to it in your Vite project. See this answer
Upvotes: 0