Repository navigation
Open
Labels
kind/bugrelated to a bugrelated to a bug
Description
I have tried to use this library but when I run my code I get the following error in the browser console:
index.3240d547.js:10 Uncaught (in promise) TypeError: oe.URLSearchParams is not a constructor
at je (index.3240d547.js:10:69597)
at a.Translator.translateText (index.3240d547.js:10:73014)
at Le (index.3240d547.js:10:71558)
Desktop (please complete the following information):
- OS: Windows 10
- Browser Electron/19.1.8
- Version [e.g. 22]
- Node 16.15.0
Additional context
I'm using typescript and have no errors when I build my app - only when I run it. However, I'm not a professional programmer so it's possible I've installed the wrong version of something. My tsconfig.json file is below:
{
"compilerOptions": {
"lib": [
"es2021",
"dom"
],
"module": "commonjs",
"target": "es2021",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node"
}
}
and my package.json
{
"name": "logseq-deepl-integration",
"version": "0.0.1",
"description": "Translate selected blocks via deepl",
"main": "dist/index.html",
"targets": {
"main": false
},
"scripts": {
"build": "parcel build --no-source-maps index.html --public-url ./",
"dev": "parcel build --no-optimize index.html --public-url ./"
},
"author": "dcoales",
"license": "MIT",
"dependencies": {
"@logseq/libs": "^0.0.10",
"deepl-node": "^1.7.3"
},
"logseq": {
"id": "logseq-deepl",
"title": "Logseq Deepl Integration",
"author": "dcoales",
"description": "Translate selected blocks via deepl"
},
"devDependencies": {
"@types/jest": "^29.0.3",
"@types/node": "^18.11.9",
"buffer": "^5.5.0",
"events": "^3.3.0",
"parcel": "^2.8.0",
"path-browserify": "^1.0.1",
"punycode": "^1.4.1",
"querystring-es3": "^0.2.1",
"stream-http": "^3.2.0",
"ts-node": "^10.9.1",
"typescript": "^4.8.3",
"url": "^0.11.0",
"util": "^0.12.5"
}
}
I'm running this as a plugin to a tool called LogSeq. The plugin code is below. Any help would be much appreciated. Thanks.
import '@logseq/libs';
import {BlockEntity} from "@logseq/libs/dist/LSPlugin";
import { SettingSchemaDesc } from '@logseq/libs/dist/LSPlugin.user';
import * as deepl from 'deepl-node';
import {TextResult} from "deepl-node";
/**
* entry
*/
function main() {
logseq.useSettingsSchema(settings);
logseq.Editor.registerSlashCommand('Get Jira Details for Selection', (_) => {
return translate();
})
logseq.App.registerCommand('deeplTranslate', {
key: 'deeplTranslate',
label: 'Translate the selected lines',
desc: 'Get translations for each of the currently selected lines',
keybinding: {binding: 'mod+alt+t'}
}, (e) => {
return translate();
})
}
async function translate() {
let selection: BlockEntity[] | null = await logseq.Editor.getSelectedBlocks();
//console.log(selection);
if (!selection || selection.length === 0) {
const block: BlockEntity | null = await logseq.Editor.getCurrentBlock();
if (block){
selection = [block];
}
}
const lines:string[] = [];
if (selection){
for (let b of selection){
lines.push(b.content);
}
}
const authKey = logseq.settings?.APIToken;
const translator = new deepl.Translator(authKey);
const results:TextResult[] = await translator.translateText(lines,null,logseq.settings?.language);
results.map((result: deepl.TextResult) => {
console.log(result.text);
});
}
const settings: SettingSchemaDesc[] = [
{
key: "language",
description: "The language for the translated text",
type: "string",
default: "pl",
title: "Translated text language",
},
{
key: "APIToken",
description: "Deepl API token",
type: "string",
default: "",
title: "Deepl API token",
}
];
logseq.ready(main).catch(console.error);
Reacted by tomsour1s, Klein Petr and Maximilian Beck
Metadata
Metadata
Assignees
Labels
kind/bugrelated to a bugrelated to a bug
Activity
tomsour1s commentedon Jan 9, 2023
Same Problem.
blandinf commentedon Jan 13, 2023
same problem
teh0 commentedon Jan 13, 2023
Same problem
usbme commentedon Jan 15, 2023
Same problem
glumb commentedon Jan 19, 2023
How is this labelled as enhancement when it is clearly a bug? 😀
We are running into the same error with node 14.18.1
dsokopp commentedon Jan 24, 2023
same issue here. Running into the error with node 16.x and 18.13.0
dsokopp commentedon Mar 1, 2023
Any updates on this @daniel-jones-deepl? Cant't use this library with the bug and our configuration..
MariusGoth commentedon Mar 29, 2023
@daniel-jones-deepl
Are there any updates on this issue?
seekuehe commentedon Apr 17, 2023
Daniel is out at the moment, but our team will look into this
JanEbbing commentedon Jun 9, 2023
A workaround is to put
at the top of the file (e.g. at the end of the imports, outside the main function). That allows me to translate with the plugin. The issue is webpack injecting a different version of url, I am investigating a clean way to fix this.