question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

url_1.URLSearchParams is not a constructor

See original GitHub issue

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:

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:closed
  • Created a year ago
  • Reactions:5
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
daniel-jones-deeplcommented, Jun 30, 2022

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.

0reactions
DhammaChartscommented, Jul 4, 2022

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 😉

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found