Skip to content

SSR with Next.js error: self is not defined #1863

@hoodsy

Description

@hoodsy
import Hls from 'hls.js'

throws the following error for me when included in my Next.js build:

{ ReferenceError: self is not defined
    at getSelfScope (src/utils/get-self-scope.js:5:4)
    at Object.HlsEvents.MEDIA_ATTACHING (src/utils/logger.js:30:15)
    at __webpack_require__ (webpack:/webpack/bootstrap efa5788fc79df7e901a6:19:0)
    at Object.moduleNameReqExp (node_modules/hls.js/dist/hls.js:5862:14)
    at __webpack_require__ (webpack:/webpack/bootstrap efa5788fc79df7e901a6:19:0)
    at node_modules/hls.js/dist/hls.js:73:18
    at node_modules/hls.js/dist/hls.js:76:10
    at webpackUniversalModuleDefinition (webpack/universalModuleDefinition:3:0)
    at Object.<anonymous> (webpack/universalModuleDefinition:10:1)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18) sourceMapsApplied: true }

I pulled in the latest PR supporting universal builds (#1841), but still get the same error. I'm currently working around this issue by requiring hls.js in componenDidMount:

componentDidMount() {
  const Hls = require('hls.js')
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions