adams85 / bundling

A library for optimizing and bundling web assets of ASP.NET Core applications.
MIT License
44 stars 7 forks source link

JS: Multiple mobile versions give syntax errors after bundeling. #16

Closed iJoris closed 2 years ago

iJoris commented 2 years ago

Getting multiple errors from sentry on syntax errors after bundeling. Just tested on iPhone 11 pro 13.2, and the not-bundeled JS works perfectly, but after bundeling gives a syntax error. image image

Code: target.forEach((el)=>{ if (el.name.includes(',')) { const arr=el.name.split(','); arr.forEach((str)=>{ const sec=window.data.find(x=>x.name=== str); if (sec) { result.push(sec.id); } } ); } else { result.push(el.id); } } ); result.forEach((id)=>{ dowork(id); } ); }

iJoris commented 2 years ago

Found out that the problem was Optional chaining.

adams85 commented 2 years ago

Do I understand correctly that the error occurs in bundled and minified files?

If so, which minimizer do you use? NUglify or WebMarkupMin? Do you use ES6 module bundling?

iJoris commented 2 years ago

@adams85 Yes, I use WebMarkupMin. I've tested it with the ES6 package Karambolo.AspNetCore.Bundling.EcmaScript. But no luck.

For now, I've just removed the '?' with simple if statements.

adams85 commented 2 years ago

Karambolo.AspNetCore.Bundling.EcmaScript is for bundling JavaScript modules. If you doesn't use JavaScript modules, there's no point in consuming this package.

It seems likely that WebMarkupMin doesn't handle the optional chaining operator well. However, you can try NUglify instead of that. If that doesn't work either, you can even try to add a direct reference to the latest version (1.17.10) of the NUglify package to your project because the latest release of Karambolo.AspNetCore.Bundling.NUglify references a bit outdated version (1.16.0) of NUglify. (Since a direct reference would force the latest version to be used.)

iJoris commented 2 years ago

Karambolo.AspNetCore.Bundling.EcmaScript is for bundling JavaScript modules. If you doesn't use JavaScript modules, there's no point in consuming this package.

It seems likely that WebMarkupMin doesn't handle the optional chaining operator well. However, you can try NUglify instead of that. If that doesn't work either, you can even try to add a direct reference to the latest version (1.17.10) of the NUglify package to your project because the latest release of Karambolo.AspNetCore.Bundling.NUglify references a bit outdated version (1.16.0) of NUglify. (Since a direct reference would force the latest version to be used.)

Cheers, going to try that! Thanks for the quick replies.