url_1.URLSearchParams is not a constructor
See original GitHub issueHi,
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
:
import './style.css'
import * as deepl from 'deepl-node';
const authKey = "...-...-...-...-...:fx"; // 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 !
})();
I get the following error:
Uncaught (in promise) TypeError: url_1.URLSearchParams is not a constructor
at buildURLSearchParams (index.js:123:26)
at Translator.translateText (index.js:354:22)
at main.js?t=1656189862004:12:37
at main.js?t=1656189862004:14:3
I have a free account with DeepL
Thanks! (I’m pretty new to this 😉
Issue Analytics
- State:
- Created a year ago
- Reactions:5
- Comments:5 (2 by maintainers)
Top Results From Across the Web
URLSearchParams is not a constructor in ReactJS
This happens when react import UrlSearchParams from 'url' So you have to remove this and try it. It will definitely work.
Read more >TypeError: URLSearchParams is not a constructor · Issue #913
Hey all, I am using: https://nodejs.org/api/url.html#url_url_searchparams but I get this error: TypeError: URLSearchParams is not a ...
Read more >URLSearchParams is not a constructor in ReactJS-Reactjs
This happens when react import UrlSearchParams from 'url' So you have to remove this and try it. It will definitely work. ... I...
Read more >URLSearchParams() - Web APIs - MDN Web Docs
The URLSearchParams() constructor creates and returns a new URLSearchParams object.
Read more >URLSearchParams / Jules Blom - Observable
The URLSearchParams constructor does not parse full URLs. ... toString(), Returns a string containing a query string suitable for use in a URL,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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. Thedeepl-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.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 😉