fent / node-ytdl-core

YouTube video downloader in javascript.
MIT License
4.48k stars 793 forks source link

Angular Electron not building on 2.1.5 Unexpected token: punc () #645

Closed arcovoltaico closed 4 years ago

arcovoltaico commented 4 years ago

On 2.1.5 my electron angular 7 app runs when npm start, but on production mode it fails like this: ERROR in main.cd7adcc1ce764ef292fd.js from Terser Unexpected token: punc ()) [./node_modules/ytdl-core/lib/info.js:147,0][main.cd7adcc1ce764ef292fd.js:96082,4] My typescript target is es2015

digimezzo commented 4 years ago

This issue also happens in version 3.1.0, but in another file: sig.js. When building an Electron app that uses ytdl-core 3.1.0 I get this error:

ERROR in main.4e5acc6baa2efc593b6a.js from Terser
Unexpected token: punc ()) [./node_modules/ytdl-core/lib/sig.js:107,0][main.4e5acc6baa2efc593b6a.js:71290,0]
fent commented 4 years ago

how is it built? does electron use webpack to build? if so, what does the config file look like?

digimezzo commented 4 years ago

I created a pull request that fixes the issue. It is caused by a trailing comma in sig.js just before the brackets ")". Unfortunately, the pull request checks fail because lint expects the trailing comma. That seems incorrect to me.

digimezzo commented 4 years ago

I fixed the pull request. Lint requires a trailing comma after the last element of an array, or variable definition, if the end bracket is on another line than the last array element or variable definition.

Putting the comma there, however, breaks the webpack build. This seems caused by a rule in the terser webpack plugin. I found an identical issue here: https://github.com/vega/vega/issues/2645

arcovoltaico commented 4 years ago

Thanks so much! But, as I am not seeing a 2.1.6 release, what I need to put on my package.json to use the fixed 2.* version?

fent commented 4 years ago

just published v3.1.1

arcovoltaico commented 4 years ago

Any chance of a 2.1.6? As 3 version does not work with old Angular, and I was planning to update my project to 9 in 1-2 months ....

fent commented 4 years ago

it doesn't? the major "breaking" change from v3.0.0 was that it now warns when using a callback or a deprecated property from info

arcovoltaico commented 4 years ago

I think the problem is I can't update the target from es5, because Material Design 7 Tables won´t work. So , 3.0.1 fail because Omit is not present in this TS version .... I think it would be great to fix the 2 version as a ES5 compatible one.

node_modules/ytdl-core/typings/index.d.ts(163,70): error TS2304: Cannot find name 'Omit'.

fent commented 4 years ago

how about updating ts? is that possible without updating the target?

arcovoltaico commented 4 years ago

My bad. I forget to add that I tried it, but it's not feasible: ERROR in The Angular Compiler requires TypeScript >=3.1.1 and <3.3.0 but 3.5.3 was found instead. As until 3.5 Omit is not available ....

fent commented 4 years ago

ok, v2.1.6 published :)

arcovoltaico commented 4 years ago

Thanks so much! Sadly it keeps failing. And I am not longer able to spot the error, just this

ERROR in main.787631c4970caa41157a.js from Terser
Unexpected token: punc ()) [main.787631c4970caa41157a.js:95184,4]  

I reckon that if it's going to take huge effort to fix it, I'd rather work upgrading from Angular 7 to 9 or 10 .

fent commented 4 years ago

if it's like the last issue where it fails to compile a backtick followed by a comma, it could be this line

https://github.com/fent/node-ytdl-core/blob/master/lib/index.js#L109

although that is an object, not a function call. maybe worth a try to remove the comma and see if it compiles. otherwise, I'm out of ideas. wish the error was more specific on where it failed.

digimezzo commented 4 years ago

It is possible to make the error more descriptive by adding --named-chunks --verbose --build-optimizer=false --source-map to the angular build command. By doing so, I get this error with v2.1.6 (which seems to be the original error that was reported):

ERROR in main.1d34fc26139041177e8f.js from Terser
Unexpected token: punc ()) [./node_modules/ytdl-core/lib/info.js:147,0][main.1d34fc26139041177e8f.js:67202,4]

The error tells us that it found an unexpected end bracket ")". It's always the character which is between the brackets in the punc() object that is unexpected. In this case: punc ()). The bracket is unexpected due to the comma on line 146 in info.js I created a pull request to fix the v2 branch.

arcovoltaico commented 4 years ago

2.1.7 works as a charm, thanks so much for fixing it, and sorry for not having done it myself, crazy times here.