Skip to content

v1.2.5 throws an error in a next.js production build #5015

Closed
@iscekic

Description

@iscekic

What version of Hls.js are you using?

v1.2.5

What browser (including version) are you using?

Chrome Version 107.0.5304.87 (Official Build) (x86_64)

What OS (including version) are you using?

MacOS Ventura 13.0

Test stream

/

Configuration

{
  maxBufferSize: 10 * 1000 * 1000,
}

Additional player setup steps

/

Checklist

  • The issue observed is not already reported by searching on Github under https://github.com/video-dev/hls.js/issues
    The issue occurs in the stable client (latest release) on https://hls-js.netlify.com/demo and not just on my page
    The issue occurs in the latest client (main branch) on https://hls-js-dev.netlify.com/demo and not just on my page
    The stream has correct Access-Control-Allow-Origin headers (CORS)
    There are no network errors such as 404s in the browser console when trying to play the stream

Steps to reproduce

  1. Add hls.js as a dependency
  2. Lazy load the video component using hls.js (https://nextjs.org/docs/advanced-features/dynamic-import)
  3. Attempt to play a stream

Expected behaviour

Stream plays

What actually happened?

Stream does not play

Console output

_app-cdf6bbbc63cadad3.js:196 [log] > Debug logs enabled for "Hls instance"
_app-cdf6bbbc63cadad3.js:196 [log] > attachMedia
_app-cdf6bbbc63cadad3.js:196 [log] > [buffer-controller]: Media source opened
_app-cdf6bbbc63cadad3.js:196 [log] > [subtitle-stream-controller]: STOPPED->IDLE
_app-cdf6bbbc63cadad3.js:196 [log] > stopLoad
_app-cdf6bbbc63cadad3.js:196 [log] > [subtitle-stream-controller]: IDLE->STOPPED
_app-cdf6bbbc63cadad3.js:196 [log] > loadSource:REDACTED_URL
_app-cdf6bbbc63cadad3.js:196 [log] > [stream-controller]: Trigger BUFFER_RESET
_app-cdf6bbbc63cadad3.js:196 [log] > [level-controller]: manifest loaded, 3 level(s) found, first bitrate: 2450000
_app-cdf6bbbc63cadad3.js:196 [log] > 1 bufferCodec event(s) expected
_app-cdf6bbbc63cadad3.js:196 [log] > startLoad(-1)
_app-cdf6bbbc63cadad3.js:196 [log] > [level-controller]: switching to level 2 from -1
_app-cdf6bbbc63cadad3.js:196 [log] > [level-controller]: Attempt loading level index 2 with URL-id 0 REDACTED_URL
_app-cdf6bbbc63cadad3.js:196 [log] > [stream-controller]: STOPPED->IDLE
_app-cdf6bbbc63cadad3.js:196 [log] > [subtitle-stream-controller]: STOPPED->IDLE
_app-cdf6bbbc63cadad3.js:196 [log] > [stream-controller]: Level 2 loaded [0,226], cc [0, 0] duration:1357.287
_app-cdf6bbbc63cadad3.js:196 [log] > [buffer-controller]: Updating Media Source duration to 1357.287
_app-cdf6bbbc63cadad3.js:196 [log] > [stream-controller]: Loading fragment 0 cc: 0 of [0-226] level: 2, target: 0
_app-cdf6bbbc63cadad3.js:196 [log] > [stream-controller]: IDLE->FRAG_LOADING
_app-cdf6bbbc63cadad3.js:196 [log] > demuxing in webworker
_app-cdf6bbbc63cadad3.js:196 [log] > [transmuxer-interface, main]: Starting new transmux session for sn: 0 p: -1 level: 2 id: 1
        discontinuity: true
        trackSwitch: true
        contiguous: false
        accurateTimeOffset: true
        timeOffset: 0
        initSegmentChange: true
_app-cdf6bbbc63cadad3.js:196 [log] > [stream-controller]: Loaded fragment 0 of level 2
_app-cdf6bbbc63cadad3.js:196 error Error: mse hls error - otherError - internalException
    at t.<anonymous> (7541.e9af46aaa854771f.js:1:1647)
    at o.emit (ddc9e94f.1b6b059d26ad8f5d.js:1:368752)
    at y.emit (ddc9e94f.1b6b059d26ad8f5d.js:1:238332)
    at y.trigger (ddc9e94f.1b6b059d26ad8f5d.js:1:238402)
    at c.onerror (ddc9e94f.1b6b059d26ad8f5d.js:1:206007)

The exception itself is:

Error: Uncaught SyntaxError: Unexpected token '{'  (blob:http://localhost:3000/4ac92d4b-88cd-4f3e-adbc-04d3746f5906:1)
    at c.onerror (http://localhost:3000/_next/static/chunks/ddc9e94f.1b6b059d26ad8f5d.js:1:206140)

Contents of http://localhost:3000/_next/static/chunks/ddc9e94f.1b6b059d26ad8f5d.js:

((function(){var t={"./src/demux/transmuxer-worker.ts": "./src/demux/transmuxer-worker.ts"(t,e,r){"use strict";r.r(e),r.d(e,{default:()=>o});var i=r(/*! ../demux/transmuxer */ "./src/demux/transmuxer.ts"),n=r(/*! ../events */ "./src/events.ts"),a=r(/*! ../utils/logger */ "./src/utils/logger.ts"),s=r(/*! eventemitter3 */ "./node_modules/eventemitter3/index.js");function o(t){var e=new s.EventEmitter,r=function(e,r){t.postMessage({event:e,data:r})};e.on(n.Events.FRAG_DECRYPTED,r),e.on(n.Events.ERROR,r);var o=function(){var t=function(t){var e=function(e){r("workerLog",{logType:t,message:e})};a.logger[t]=e};for(var e in a.logger)t(e)};t.addEventListener("message",function(n){var s=n.data;switch(s.cmd){case"init":var u=JSON.parse(s.config);t.transmuxer=new i.default(e,s.typeSupported,u,s.vendor,s.id),(0,a.enableLogs)(u.debug,s.id),o(),r("init",null);break;case"configure":t.transmuxer.configure(s.config);break;case"demux":var c=t.transmuxer.push(s.data,s.decryptdata,s.chunkMeta,s.state);(0,i.isPromise)(c)?c.then(function(e){l(t,e)}):l(t,c);break;case"flush":var h=s.chunkMeta,f=t.transmuxer.flush(h);(0,i.isPromise)(f)?f.then(function(e){d(t,e,h)}):d(t,f,h)}})}function l(t,e){if(!(r=e.remuxResult).audio&&!r.video&&!r.text&&!r.id3&&!r.initSegment)return!1;var r,i=[],n=e.remuxResult,a=n.audio,s=n.video;return a&&u(i,a),s&&u(i,s),t.postMessage({event:"transmuxComplete",data:e},i),!0}function u(t,e){e.data1&&t.push(e.data1.buffer),e.data2&&t.push(e.data2.buffer)}function d(t,e,r){e.reduce(function(e,r){return l(t,r)||e},!1)||t.postMessage({event:"transmuxComplete",data:e[0]}),t.postMessage({event:"flush",data:r})}}},e={};function r(i){var n=e[i];if(void 0!==n)return n.exports;var a=e[i]={exports:{}};return t[i].call(a.exports,a,a.exports,r),a.exports}r.m=t,r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,{a:e}),e},r.d=function(t,e){for(var i in e)r.o(e,i)&&!r.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var i=r("./src/demux/transmuxer-worker.ts");return i.default||i})())(self);

Chrome media internals output

No response

Activity

added
Needs TriageIf there is a suspected stream issue, apply this label to triage if it is something we should fix.
on Nov 8, 2022
iscekic

iscekic commented on Nov 8, 2022

@iscekic
Author

Other notes:

  • no issues in v1.2.4
  • next.js v13.0.2

If this is as issue for the next.js team, please let me know and close this issue. Thanks! 👍

robwalch

robwalch commented on Nov 9, 2022

@robwalch
Collaborator

Probably a result of upgrading to Webpack 5 (webworkify-webpack) #5007.

Looks like you re-bundling hls.js?

Can you provide a sample page that isolates/reproduces the issue? @iscekic I am not familiar with next.js setup so the steps to reproduce set a pretty high bar. If provided a page that reproduces the issue, I can debug through how the worker JS is composed here, and may be able to come up with a fix.

Workarounds for v1.2.5: disable worker enableWorker: false, or use hls.min.js without re-bundling it.

robwalch

robwalch commented on Nov 9, 2022

@robwalch
Collaborator

Not a fix for the Webpack 5 webworkify port (#5007), but it will at least keep playback running in the event of an exception like this #5016

iscekic

iscekic commented on Nov 14, 2022

@iscekic
Author

Here's a minimal reproduction repo (default nextjs config): https://github.com/iscekic/hlsjs-repro

yarn build
yarn start

It does look like some sort of transformation is happening. I'll look into whether it's possible to selectively disable it for a package.

iscekic

iscekic commented on Nov 15, 2022

@iscekic
Author

Looks like this is an issue with the swc minifier next.js uses. Setting swcMinify: false in next.config.js fixes the issue (see vercel/next.js#42852).

20 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugConfirmedBug report confirmed or reproduced.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @iDVB@robwalch@karlhorky@iscekic@kdy1

        Issue actions

          v1.2.5 throws an error in a next.js production build · Issue #5015 · video-dev/hls.js