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

How to import Hls.js from another file #2911

Closed
hnrazevedo opened this issue Jul 21, 2020 · 6 comments
Closed

How to import Hls.js from another file #2911

hnrazevedo opened this issue Jul 21, 2020 · 6 comments
Labels

Comments

@hnrazevedo
Copy link

What do you want to do with Hls.js?
I would like to import the hls.js file into another javascript file

What have you tried so far?

I tried importart like this:
import * as Hls from "./hls.js";

However, give the following error on the console:


Uncaught TypeError: Cannot set property 'Hls' of undefined
    at webpackUniversalModuleDefinition (universalModuleDefinition:9)
    at universalModuleDefinition:10

And the console points to the highlighted line:

(function webpackUniversalModuleDefinition(root, factory) {
	if(typeof exports === 'object' && typeof module === 'object')
		module.exports = factory();
	else if(typeof define === 'function' && define.amd)
		define([], factory);
	else if(typeof exports === 'object')
		exports["Hls"] = factory();
	else
--->		root["Hls"] = factory();
})(this, function() {
return 
@robwalch
Copy link
Collaborator

robwalch commented Jul 24, 2020

It's a default export, so:
import Hls from 'hls.js

@hnrazevedo
Copy link
Author

hnrazevedo commented Jul 25, 2020

From the error, on the Chrome console give the following message:

Uncaught TypeError: Failed to resolve module specifier "hls.js". Relative references must start with either "/", "./", or "../".

If I try:

import Hls from './hls.js';

Returns the error:

Uncaught SyntaxError: The requested module './hls.js' does not provide an export named 'default'

It is worth mentioning that I am importing a simple js file from a player I am developing

@stale stale bot added the Stale label Aug 15, 2020
@video-dev video-dev deleted a comment from stale bot Aug 16, 2020
@robwalch
Copy link
Collaborator

There is no ES6 export in the JavaScript dist. It's a UMD module (amd, require, or global). See #2910

@hnrazevedo
Copy link
Author

I used the following syntax and solved my problem:
import "./hls.js";

@stale stale bot removed the Stale label Aug 17, 2020
@kenianbei
Copy link

I also had to set tsconfig compiler option to "allowSyntheticDefaultImports": false in order for the default import to work.

@asmanp2012
Copy link

asmanp2012 commented Apr 10, 2022

Hi
when I use typescript my scripts were built but give me this error on the browser:
Uncaught SyntaxError: The requested module './../../hls.js/dist/hls.js' does not provide an export named 'default'
how can I fix that? @robwalch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants