Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: Invalid or unexpected token #1261

Open
matthieuEv opened this issue Nov 14, 2023 · 19 comments
Open

SyntaxError: Invalid or unexpected token #1261

matthieuEv opened this issue Nov 14, 2023 · 19 comments

Comments

@matthieuEv
Copy link

I was working on a project, when suddently, ytdl-core stoped working. So i created a new project to try a simple code:

const fs = require('fs');
const ytdl = require('ytdl-core');

const url = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';

ytdl(url)
  .pipe(fs.createWriteStream('video.mp4'));

I have the latest package of ytdl: ytdl-core@4.11.5

But when i run the code: node index.js, i get the error:

evalmachine.<anonymous>:426
koa=function(a,b,c,d){var e=null;switch(b){case "JSON":try{var f=c.responseText}catch(h){throw d=Error("Error reading responseText"),d.params=a,JB(d),h;}a=c.getResponseHeader("Content-Type")||"";f&&0<=a.indexOf("json")&&(")]};gma(ncode);
                                                                                                                                                                                                                             ^^^^^^^^^^^^^^^^

SyntaxError: Invalid or unexpected token
    at new Script (node:vm:94:7)
    at exports.decipherFormats (/tmp/test/node_modules/ytdl-core/lib/sig.js:116:51)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Promise.all (index 0)
    at async exports.getInfo (/tmp/test/node_modules/ytdl-core/lib/info.js:401:17)
Emitted 'error' event on PassThrough instance at:
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v18.17.1

I'm not sure what appened, but it was working just fine, and suddently, this appear out of knowhere, without modifying anything.

@juliand665
Copy link

I'm getting the same error in my project without changing anything. Presumably YouTube changed something up, but I certainly didn't expect that to produce an error like this!

@ftrbnd
Copy link

ftrbnd commented Nov 14, 2023

Yeah I also just started getting this error today. My app was working fine yesterday, and one of my users just notified me that one my features that uses ytdl-core wasn't working. Hope it gets fixed soon!

@Exorcismus
Copy link

same error

@akrom123
Copy link

I have the same error :(

@avallois
Copy link

avallois commented Nov 14, 2023

Same ! Showing like this for me:

evalmachine.<anonymous>:426
koa=function(a,b,c,d){var e=null;switch(b){case "JSON":try{var f=c.responseText}catch(h){throw d=Error("Error reading responseText"),d.params=a,JB(d),h;}a=c.getResponseHeader("Content-Type")||"";f&&0<=a.indexOf("json")&&(")]};gma(ncode);
                                                                                                                                                                                                                             ^^^^^^^^^^^^^^^^

SyntaxError: Invalid or unexpected token
    at new Script (node:vm:93:7)
    at Object.exports.decipherFormats (/usr/src/app/node_modules/ytdl-core/lib/sig.js:116:51)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Promise.all (index 0)
    at async exports.getInfo (/usr/src/app/node_modules/ytdl-core/lib/info.js:401:17)

@Exorcismus
Copy link

Exorcismus commented Nov 14, 2023

as a quick investigation, I beleive the error is related to funcion extractNCode in sig.js

oa=function(a,b,c,d){var e=null;switch(b){case "JSON":try{var f=c.responseText}catch(h){throw d=Error("Error reading responseText"),d.params=a,JB(d),h;}a=c.getResponseHeader("Content-Type")||"";f&&0<=a.indexOf("json")&&(")]}'\n"===f.substring(0,5)&&(f=f.substring(5)),e=JSON.parse(f));break;case "XML":if(a=(a=c.responseXML)?moa(a):null)e={},g.cc(a.getElementsByTagName("*"),function(h){e[h.tagName]=noa(h)})}d&&ooa(e);

is being mis-parsed

could be related to function utils.cutAfterJS failing to parse (")]}'\n"===f.substring(0,5)&&(f=f.substring(5)),e=JSON.parse(f))

@LucasSantos14
Copy link

I'm also facing this problem...

@juanfjk
Copy link

juanfjk commented Nov 15, 2023

Same issue: Invalid or unexpected token

@DerekCounihan
Copy link

DerekCounihan commented Nov 15, 2023

+1
Screenshot 2023-11-15 at 01 08 15

@Zuz111
Copy link

Zuz111 commented Nov 15, 2023

#1251 (comment)

Try it. Work for me.

@duykhanh09103
Copy link

+1 i got it today too without changing any of the code

@timfong888
Copy link

timfong888 commented Nov 15, 2023

I got a similar error without changing any code as well:

koa=function(a,b,c,d){var e=null;switch(b){case "JSON":try{var f=c.responseText}catch(h){throw d=Error("Error reading responseText"),d.params=a,JB(d),h;}a=c.getResponseHeader("Content-Type")||"";f&&0<=a.indexOf("json")&&(")]};gma(ncode);"
severity: "ERROR"
textPayload: "SyntaxError: Invalid or unexpected token
    at new Script (node:vm:94:7)
    at exports.decipherFormats (/workspace/node_modules/ytdl-core/lib/sig.js:116:51)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Promise.all (index 0)
    at async exports.getInfo (/workspace/node_modules/ytdl-core/lib/info.js:401:17)"
timestamp: "2023-11-14T21:57:40.661609Z"
trace: "projects/sophia-db784/traces/d776aacfe766abe87cba7cc4def33496"

@libhide
Copy link

libhide commented Nov 15, 2023

Seeing this issue as well without any changes to code.

@MelleNooijen
Copy link

I get the following error. Same with @khlevon 's PR sadly.

Error occurred in handler for 'main:getVideoInfo': evalmachine.<anonymous>:426
koa=function(a,b,c,d){var e=null;switch(b){case "JSON":try{var f=c.responseText}catch(h){throw d=Error("Error reading responseText"),d.params=a,JB(d),h;}a=c.getResponseHeader("Content-Type")||"";f&&0<=a.indexOf("json")&&(")]};gma(ncode);
                                                                                                                                                                                                                             ^^^^^^^^^^^^^^^^

SyntaxError: Invalid or unexpected token
    at new Script (node:vm:100:7)
    at Object.exports.decipherFormats (/Users/melle/Git/JYTDownload/node_modules/ytdl-core/lib/sig.js:116:51)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Promise.all (index 0)
    at async exports.getInfo (/Users/melle/Git/JYTDownload/node_modules/ytdl-core/lib/info.js:401:17)

@fpsone
Copy link

fpsone commented Nov 15, 2023

You can try this solution: #1252 (comment)

@LucasSantos14
Copy link

This way you solved my problem!
#1252 (comment)

@avallois
Copy link

You can try this solution: #1252 (comment)

This worked for me, thanks a lot

@itJunky
Copy link

itJunky commented Nov 16, 2023

Same error, and solution with npm i ytdl-core@npm:@distube/ytdl-core doesn't help me (

@johanbry
Copy link

Same problem, but using this patched version worked for me, from PR #1217.

"ytdl-core": "git+ssh://git@github.com:khlevon/node-ytdl-core.git#v4.11.4-patch.2"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests