ybd-project / ytdl-core

Fast and secure YouTube downloader for JavaScript and TypeScript
MIT License
28 stars 5 forks source link

SyntaxError: Unexpected token - Getting error in Ubantu (16.04) #19

Closed Topiya closed 2 weeks ago

Topiya commented 2 months ago

I am using v5.1.2 version of @ybd-project/ytdl-core which is working fine in Windows but getting below error Ubantu. Node version is same in both systems as mentioned below.

/@ybd-project/ytdl-core/package/YtdlCore.js:68
    options ??= {};
             ^
SyntaxError: Unexpected token ?

Can anyone please help me solve this problem?

ybd-project commented 2 months ago

Thank you for your report. I will install Ubuntu on the virtual machine and try it.

Topiya commented 2 months ago

Thank you. I'd appreciate it if you could reply soon, as I need the solution urgently.

ybd-project commented 2 months ago

It works fine in my environment. Please let me know what code you are implementing as best you can.

Topiya commented 2 months ago

Ubantu verion: 16.04

const YtdlCore = require("@ybd-project/ytdl-core");

app.get('/ybdtest', async function (req, res) {
 const fs = require('fs');
 const ytdl = new YtdlCore({});
  // Download a video
 ytdl.download('https://www.youtube.com/watch?v=aqz-KE-bpKQ').pipe(fs.createWriteStream('video.mp4'));
});
Topiya commented 2 months ago

Also I would like to mention that I am getting above error on run the script 'node download.js', without even accessing route.

ybd-project commented 2 months ago
const YtdlCore = require("@ybd-project/ytdl-core");

but change it to the following

const { YtdlCore } = require("@ybd-project/ytdl-core");
Topiya commented 2 months ago

I have tried with both of it but getting same error.

So I have tried lower version of @ybd-project/ytdl-core 5.0.7 with node 14.21.3 using const YtdlCore = require("@ybd-project/ytdl-core"); which is also giving same error.

ybd-project commented 2 months ago

Maybe the problem is the "??=" syntax (if the value is empty, assign it). So we will release a version (v5.1.3) by the end of tomorrow that does not use this syntax.

ybd-project commented 2 months ago

v5.1.3 has been released. Please check to see if the problem has been fixed.

Topiya commented 2 months ago

Using latest plugin v5.1.3, I have checked with node 20.17 in Ubantu (16.04) . Still getting same error.

/@ybd-project/ytdl-core/package/YtdlCore.js:68
    options ??= {};
            ^^^

SyntaxError: Unexpected token '??='
Neelam1990 commented 2 months ago

I am using the same Ubuntu version with node 14 and ybd-project/ytdl-core 5.1.3 and i am experiencing the same error. Is there a compatible version for node 14?

ybd-project commented 2 months ago

Since the “??=” was still there, we removed it all and released v5.1.4.

ybd-project commented 2 months ago

I am using the same Ubuntu version with node 14 and ybd-project/ytdl-core 5.1.3 and i am experiencing the same error. Is there a compatible version for node 14?

The "??=" syntax in question was supported starting with Node.js 16, so I believe the error occurs in 14. I think it is ok since we removed "??=" completely in v5.1.4.

Topiya commented 2 months ago

I am getting below error on accessing my node route.

at async Function.generatePoToken (/home/ubuntu/api/node_modules/@ybd-project/ytdl-core/package/core/PoToken.js:8:26)
(node:7840) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection,

Below is my node GET route code:

const { YtdlCore } = require("@ybd-project/ytdl-core");

app.get('/ybdtest', async function (req, res) {   // I have tried here by removing async also
  const fs = require('fs');
  const ytdl = new YtdlCore({});
  ytdl.download('https://www.youtube.com/watch?v=aqz-KE-bpKQ').pipe(fs.createWriteStream('video.mp4'));
});
ybd-project commented 2 months ago

It seems to be due to the fact that error handling is not set up when poToken generation fails. A version (v5.1.4-2) fixing this will be released soon.

Neelam1990 commented 2 months ago

I am using the same Ubuntu version with node 14 and ybd-project/ytdl-core 5.1.3 and i am experiencing the same error. Is there a compatible version for node 14?

The "??=" syntax in question was supported starting with Node.js 16, so I believe the error occurs in 14. I think it is ok since we removed "??=" completely in v5.1.4.

I am experiencing the same PoToken error. We are eagerly awaiting your new fixes.

ybd-project commented 2 months ago

Released. We are currently building an environment with Ubuntu 16.04 and Node.js 14 and 20.

Neelam1990 commented 2 months ago

Getting the following error after updating the new release.

(node:1824) UnhandledPromiseRejectionWarning: Error: TypeError: Object.hasOwn is not a function at Function.g.C_.create (eval at (/node_modules/youtube-po-token-generator/lib/task.js:27:18), :12362:64) at eval (eval at (/node_modules/youtube-po-token-generator/lib/task.js:27:18), :12851:6) at eval (eval at (/node_modules/youtube-po-token-generator/lib/task.js:27:18), :12856:4) at eval () at /node_modules/youtube-po-token-generator/lib/task.js:27:18 at new Promise () at Object.start (/node_modules/youtube-po-token-generator/lib/task.js:15:35) at generate (/node_modules/youtube-po-token-generator/index.js:7:34) (node:1824) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2) (node:1824) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. (node:1824) UnhandledPromiseRejectionWarning: Error: TypeError: Object.hasOwn is not a function at Function.g.C_.create (eval at (/node_modules/youtube-po-token-generator/lib/task.js:27:18), :12362:64) at eval (eval at (/node_modules/youtube-po-token-generator/lib/task.js:27:18), :12851:6) at eval (eval at (/node_modules/youtube-po-token-generator/lib/task.js:27:18), :12856:4) at eval () at /node_modules/youtube-po-token-generator/lib/task.js:27:18 at new Promise () at Object.start (/node_modules/youtube-po-token-generator/lib/task.js:15:35) at generate (/node_modules/youtube-po-token-generator/index.js:7:34) (node:1824) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4) [ ERROR ]: Failed to generate a poToken. Details: TypeError: destroy is not a function

Reason: Sign in to confirm you're not a bot

Reason: Sign in to confirm you're not a bot

Reason: Sign in to confirm you're not a bot

Reason: Sign in to confirm you're not a bot

Reason: Sign in to confirm you're not a bot (node:1824) UnhandledPromiseRejectionWarning: Error: All player APIs responded with an error. (Clients: web, webCreator, tvEmbedded, ios, android) For more information, specify YTDL_DEBUG as an environment variable. Note: This error cannot continue processing. (Details: "Sign in to confirm you're not a bot") at Function.getApiResponses (/node_modules/@ybd-project/ytdl-core/package/core/Info/apis/Player.js:48:23) at runMicrotasks () at processTicksAndRejections (internal/process/task_queues.js:95:5) at async _getBasicInfo (/node_modules/@ybd-project/ytdl-core/package/core/Info/BasicInfo.js:71:218) at async _getFullInfo (/node_modules/@ybd-project/ytdl-core/package/core/Info/FullInfo.js:24:18) (node:1824) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 7) [ ERROR ]: Failed to generate a poToken. Details: TypeError: destroy is not a function

ybd-project commented 2 months ago

The best option is to update Node.js, but if you can't, specify PoToken and VisitorData in the options.

ybd-project commented 2 months ago

Is the problem resolved?

Neelam1990 commented 2 months ago

Not yet, so we are planning to update ubuntu as well as node js.