YouTube.js icon indicating copy to clipboard operation
YouTube.js copied to clipboard

13.4.0 (Deno) - Invalid JSON in Response

Open Jelenkee opened this issue 10 months ago • 5 comments

Steps to reproduce

Run that script with Deno (2.3.3):

import { Innertube } from "npm:youtubei.js";

const tube = await Innertube.create({
  retrieve_player: false,
});
console.log(await tube.search("test", { type: "video" }));

Failure Logs

error: Uncaught (in promise) SyntaxError: Unterminated string in JSON at position 262029 (line 1 column 262030)
    at JSON.parse (<anonymous>)
    at Actions.execute (file:///home/gaus/.cache/deno/npm/registry.npmjs.org/youtubei.js/13.4.0/dist/src/core/Actions.js:91:24)
    at Object.runMicrotasks (ext:core/01_core.js:692:26)
    at processTicksAndRejections (ext:deno_node/_next_tick.ts:59:10)
    at runNextTicks (ext:deno_node/_next_tick.ts:76:3)
    at eventLoopTick (ext:core/01_core.js:185:21)
    at async Innertube.search (file:///home/gaus/.cache/deno/npm/registry.npmjs.org/youtubei.js/13.4.0/dist/src/Innertube.js:177:26)
    at async file:///home/gaus/Projects/buli/main.ts:64:13

Expected behavior

I expect a search result without errors.

Current behavior

There is an error when parsing the response.

Version

Default

Anything else?

The same error happens with await tube.getChannel("UClCIWcZNvq15p0Y-E4ToGOw").

EDIT: Works as expected with NodeJS. So probably a Deno issue.

Checklist

  • [x] I am running the latest version.
  • [x] I checked the documentation and found no answer.
  • [x] I have searched the existing issues and made sure this is not a duplicate.
  • [x] I have provided sufficient information.

Jelenkee avatar May 17 '25 12:05 Jelenkee

I don't know if it's related, but when I add the global fetch to the config, I get an error with url serialization.

const tube = await Innertube.create({
  retrieve_player: false,
  fetch: fetch
});
error: Uncaught (in promise) TypeError: Invalid URL: '[object Request]'
    at getSerialization (ext:deno_url/00_url.js:98:11)
    at new URL (ext:deno_url/00_url.js:405:27)
    at new Request (ext:deno_fetch/23_request.js:338:25)
    at ext:deno_fetch/26_fetch.js:374:29
    at new Promise (<anonymous>)
    at HTTPClient.fetch (ext:deno_fetch/26_fetch.js:370:20)
    at HTTPClient.fetch (file:///home/gaus/.cache/deno/npm/registry.npmjs.org/youtubei.js/13.4.0/dist/src/utils/HTTPClient.js:107:85)
    at Actions.execute (file:///home/gaus/.cache/deno/npm/registry.npmjs.org/youtubei.js/13.4.0/dist/src/core/Actions.js:67:79)
    at NavigationEndpoint.call (file:///home/gaus/.cache/deno/npm/registry.npmjs.org/youtubei.js/13.4.0/dist/src/parser/classes/NavigationEndpoint.js:82:28)
    at Innertube.getChannel (file:///home/gaus/.cache/deno/npm/registry.npmjs.org/youtubei.js/13.4.0/dist/src/Innertube.js:276:48)

Jelenkee avatar May 18 '25 05:05 Jelenkee

I guess the difference between node and deno is that deno uses HTTP/2

Jelenkee avatar Jun 09 '25 09:06 Jelenkee

@Jelenkee Can you please check that deno is actually using the deno entrypoint in YouTube.js when installed from npm? One way to check is whether it works correctly if you install it from denoland which only has the deno entrypoint.

absidue avatar Jun 09 '25 09:06 absidue

~~it does not exist on denoland~~

It works indeed when i use import { Innertube } from "https://deno.land/x/[email protected]/deno.ts"; That's strange.

Jelenkee avatar Jun 09 '25 18:06 Jelenkee

From the README:

import { Innertube } from 'https://deno.land/x/youtubei/deno.ts';

absidue avatar Jun 09 '25 18:06 absidue

Closing as this should be fixed with 15.0.0 (deno was using the node entrypoint instead of the deno one).

absidue avatar Jul 18 '25 21:07 absidue