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

hls.js (and hls.min.js) are not being compiled to ECMAScript5 #5288

Closed
5 tasks done
thornbill opened this issue Mar 13, 2023 · 15 comments
Closed
5 tasks done

hls.js (and hls.min.js) are not being compiled to ECMAScript5 #5288

thornbill opened this issue Mar 13, 2023 · 15 comments
Labels
Bug Confirmed Regression A bug introduced in a recent release
Milestone

Comments

@thornbill
Copy link

What version of Hls.js are you using?

v1.3.4

What browser (including version) are you using?

N/A

What OS (including version) are you using?

N/A

Test stream

No response

Configuration

{}

Additional player setup steps

No response

Checklist

Steps to reproduce

  1. Install the latest version of hls.js via npm.
  2. Run npx es-check es5 'node_modules/hls.js/dist/**/*.js'
  3. Observe the errors encountered parsing the files.

Expected behaviour

hls.js should be compiled to ECMAScript5 as stated in the README. This is particularly important for applications supporting smart TV platforms (Tizen, WebOS) that ship old versions of browser engines that do not support ES2015+ syntax.

What actually happened?

The compiled files include arrow functions that are not supported in ECMAScript5.

Console output

N/A

Chrome media internals output

No response

@thornbill thornbill added Bug Needs Triage If there is a suspected stream issue, apply this label to triage if it is something we should fix. labels Mar 13, 2023
@robwalch
Copy link
Collaborator

Please include the output you are seeing and samples from the builds.

@thornbill
Copy link
Author

thornbill commented Mar 13, 2023

I'm not sure I understand what you are requesting. I am using the build directly from npm (I am not building hls.js myself). The issue is that the builds include syntax that is not valid ES5. I can provide the output of es-check, but if you just grep the files in dist you can find there are arrow functions (()=>{}) included there. I suspect this is caused by a misconfiguration of the webpack file since I see you are targeting older browsers there (iOS/Safari 8) that definitely do not support this syntax either.

es-check output
➔ npx es-check es5 'node_modules/hls.js/dist/**/*.js'
error: ES-Check: there were 5 ES version matching errors.
info: 
          ES-Check Error:
          ----
          · erroring file: node_modules/hls.js/dist/hls-demo.js
          · error: SyntaxError: Unexpected token (11:10)
          · see the printed err.stack below for context
          ----

          SyntaxError: Unexpected token (11:10)
    at Parser.pp$4.raise (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:3460:15)
    at Parser.pp$9.unexpected (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:761:10)
    at Parser.pp$5.parseExprAtom (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2844:12)
    at Parser.pp$5.parseExprSubscripts (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2636:21)
    at Parser.pp$5.parseMaybeUnary (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2602:19)
    at Parser.pp$5.parseExprOps (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2529:21)
    at Parser.pp$5.parseMaybeConditional (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2512:21)
    at Parser.pp$5.parseMaybeAssign (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2479:21)
    at Parser.pp$5.parseExpression (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2442:21)
    at Parser.pp$5.parseParenExpression (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2913:20)
        
info: 
          ES-Check Error:
          ----
          · erroring file: node_modules/hls.js/dist/hls.js
          · error: SyntaxError: Unexpected token (11:10)
          · see the printed err.stack below for context
          ----

          SyntaxError: Unexpected token (11:10)
    at Parser.pp$4.raise (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:3460:15)
    at Parser.pp$9.unexpected (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:761:10)
    at Parser.pp$5.parseExprAtom (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2844:12)
    at Parser.pp$5.parseExprSubscripts (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2636:21)
    at Parser.pp$5.parseMaybeUnary (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2602:19)
    at Parser.pp$5.parseExprOps (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2529:21)
    at Parser.pp$5.parseMaybeConditional (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2512:21)
    at Parser.pp$5.parseMaybeAssign (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2479:21)
    at Parser.pp$5.parseExpression (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2442:21)
    at Parser.pp$5.parseParenExpression (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2913:20)
        
info: 
          ES-Check Error:
          ----
          · erroring file: node_modules/hls.js/dist/hls.light.js
          · error: SyntaxError: Unexpected token (11:10)
          · see the printed err.stack below for context
          ----

          SyntaxError: Unexpected token (11:10)
    at Parser.pp$4.raise (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:3460:15)
    at Parser.pp$9.unexpected (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:761:10)
    at Parser.pp$5.parseExprAtom (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2844:12)
    at Parser.pp$5.parseExprSubscripts (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2636:21)
    at Parser.pp$5.parseMaybeUnary (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2602:19)
    at Parser.pp$5.parseExprOps (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2529:21)
    at Parser.pp$5.parseMaybeConditional (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2512:21)
    at Parser.pp$5.parseMaybeAssign (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2479:21)
    at Parser.pp$5.parseExpression (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2442:21)
    at Parser.pp$5.parseParenExpression (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2913:20)
        
info: 
          ES-Check Error:
          ----
          · erroring file: node_modules/hls.js/dist/hls.light.min.js
          · error: SyntaxError: Unexpected token (1:221)
          · see the printed err.stack below for context
          ----

          SyntaxError: Unexpected token (1:221)
    at Parser.pp$4.raise (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:3460:15)
    at Parser.pp$9.unexpected (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:761:10)
    at Parser.pp$5.parseExprAtom (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2844:12)
    at Parser.pp$5.parseExprSubscripts (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2636:21)
    at Parser.pp$5.parseMaybeUnary (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2602:19)
    at Parser.pp$5.parseExprOps (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2529:21)
    at Parser.pp$5.parseMaybeConditional (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2512:21)
    at Parser.pp$5.parseMaybeAssign (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2479:21)
    at Parser.pp$5.parseExpression (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2442:21)
    at Parser.pp$5.parseParenExpression (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2913:20)
        
info: 
          ES-Check Error:
          ----
          · erroring file: node_modules/hls.js/dist/hls.min.js
          · error: SyntaxError: Unexpected token (1:221)
          · see the printed err.stack below for context
          ----

          SyntaxError: Unexpected token (1:221)
    at Parser.pp$4.raise (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:3460:15)
    at Parser.pp$9.unexpected (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:761:10)
    at Parser.pp$5.parseExprAtom (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2844:12)
    at Parser.pp$5.parseExprSubscripts (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2636:21)
    at Parser.pp$5.parseMaybeUnary (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2602:19)
    at Parser.pp$5.parseExprOps (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2529:21)
    at Parser.pp$5.parseMaybeConditional (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2512:21)
    at Parser.pp$5.parseMaybeAssign (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2479:21)
    at Parser.pp$5.parseExpression (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2442:21)
    at Parser.pp$5.parseParenExpression (/home/bill/Projects/Jellyfin/jellyfin-web/node_modules/acorn/dist/acorn.js:2913:20)

@robwalch robwalch added Confirmed and removed Needs Triage If there is a suspected stream issue, apply this label to triage if it is something we should fix. labels Mar 13, 2023
@robwalch
Copy link
Collaborator

Thanks @thornbill,

That's what I was looking for. I see the arrows in the webpack output and am looking into our build settings (webpack.config.js), as well as what build this regressed in.

@robwalch robwalch added this to the 1.3.5 milestone Mar 13, 2023
@robwalch robwalch added the Regression A bug introduced in a recent release label Mar 13, 2023
@robwalch
Copy link
Collaborator

Regressed in v1.2.5, most likely with the Webpack 5 upgrade.

@robwalch
Copy link
Collaborator

robwalch commented Mar 15, 2023

Hi @thornbill,

I didn't find an obvious solution converting Webpack 5 boilerplate to ES5. It looks like babel-loader transpiles the modules but not the boilerplate.

I decided to revisit migrating to Rollup and I think it addresses the issue (see #5299). What would be great is if we had a task to run the ES5 check in the project. Would this be something you could submit a PR for? Thanks!

@thornbill
Copy link
Author

Sure I would be happy to help with that. We have an automated check for Jellyfin that I should be able to adapt.

@thornbill
Copy link
Author

I opened a PR that adds a build time check of ES5 syntax here: #5301

robwalch added a commit that referenced this issue Mar 17, 2023
Add an es module target (#2910)
UMD build worker injection (#5107)
Add ES5 syntax check for UMD builds (#5301, #5288)
robwalch added a commit that referenced this issue Mar 23, 2023
Add an es module target (#2910)
UMD build worker injection (#5107)
Add ES5 syntax check for UMD builds (#5301, #5288)
robwalch added a commit that referenced this issue Mar 24, 2023
Add an es module target (#2910)
UMD build worker injection (#5107)
Add ES5 syntax check for UMD builds (#5301, #5288)
robwalch added a commit that referenced this issue Mar 27, 2023
Add an es module target (#2910)
UMD build worker injection (#5107)
Add ES5 syntax check for UMD builds (#5301, #5288)
robwalch added a commit that referenced this issue Mar 27, 2023
)

* Convert build packager to rollup
* Add an es module target (#2910)
* UMD build worker injection (#5107)
* Add ES5 syntax check for UMD builds (#5301, #5288)
* Add common rollup config
* handle `self` not existing (happens in nodejs. The check that makes sure the dist file can be required in node and not throw was failing because of this.)
* Disable coverage in CI
* Add `config.workerPath` option and "hls.worker.js" build output (#5107)
* Include transmuxer-interface id ("main" and "audio") in Web Worker setup and error logs

Co-authored-by: Tom Jenkinson <tom@tjenkinson.me>
@robwalch robwalch added the Verify Fixed An unreleased bug fix has been merged and should be verified before closing. label Mar 27, 2023
@robwalch
Copy link
Collaborator

Hi @thornbill,

Thank for the bug report and build time check. The fix is in beta https://github.com/video-dev/hls.js/releases/tag/v1.4.0-beta.1

@thornbill
Copy link
Author

Excellent! Thanks for the update!

@robwalch
Copy link
Collaborator

Closing as fixed in v1.4.0.

@robwalch robwalch removed the Verify Fixed An unreleased bug fix has been merged and should be verified before closing. label Apr 11, 2023
@IhToN
Copy link

IhToN commented Jun 21, 2023

I'm sorry to reopen this issue but I am checking and the same issue is happening over the .mjs files, they are not properly transpiled to ECMA5 and you can find out arrow functions together with const and let usage.

@robwalch
Copy link
Collaborator

@IhToN the mjs files are ES module exports. Use the UMD exports (.js files) if you want es5.

@dstreet26
Copy link
Contributor

@robwalch

Backstory

We were noticing issues on newer Tizen TV's where the video would just freeze up.

We don't have the exact TV's to test on, I'm assuming 2022 and up... 2017, 2018, and 2021 seemed fine during extensive testing during prime time hours.

Here are the models from our customers that reported this:
QN75Q60CAFXZA - Software Version: T-NKLCAKUC-1212.6,E0300025,BT-S
QN43Q60CAFXA - Software T-NKLCAKUC-1212.6 E0301500,BT-S

So we updated hls.js from 1.3.5 to 1.4.10 to see if it helped (still waiting to hear back on that)

The relevant issue

But then Tizen 2017 TV's stopped loading altogether with the debugger showing:

Unexpected token {

After trying all sorts of additional babel plugins and presets to no avail, I found that altering the node_modules/hls.js/package.json worked. Here is the postinstall script that we're going to use in our CI/CD:

// replace 2 strings in node_modules\hls.js\package.json
// replace "mjs" with "js"
// replace "module": "./dist/hls.mjs", with "module": "./dist/hls.js", in package.json
// replace "import": "./dist/hls.mjs", with "import": "./dist/hls.js", in package.json
const fs = require('fs')
const path = require('path')
const packageJsonPath = path.join(
  __dirname,
  'node_modules',
  'hls.js',
  'package.json'
)
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
packageJson.module = './dist/hls.js'
packageJson.exports['.'].import = './dist/hls.js'
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))

This feels hacky. I'm not sure what else to do. I thought you would like to know and maybe this helps others.

@robwalch
Copy link
Collaborator

Hi @dstreet26,

How are you including HLS.js in your project?

This issue was fixed in 1.4.0 for the UMD builds (files ending in .js).

When importing 'hls.js', the ES module is imported by default. It is then expected that your project transpiled all JavaScript to ES5. Unless, you point to one of the UMD files:

import Hls from 'hls.js/dist/hls.js'

@dstreet26
Copy link
Contributor

We were using:
import Hls from 'hls.js'

I didn't think to try that 🤦

I just tested import Hls from 'hls.js/dist/hls.js' on Tizen 2017 and other devices and it worked, thanks! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Confirmed Regression A bug introduced in a recent release
Projects
None yet
Development

No branches or pull requests

4 participants