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

Missing "./src/is-supported" specifier in "hls.js" package. (svelte, vite) #5593

Closed
5 tasks done
jer-0 opened this issue Jun 23, 2023 · 10 comments · Fixed by #6006
Closed
5 tasks done

Missing "./src/is-supported" specifier in "hls.js" package. (svelte, vite) #5593

jer-0 opened this issue Jun 23, 2023 · 10 comments · Fixed by #6006
Milestone

Comments

@jer-0
Copy link
Contributor

jer-0 commented Jun 23, 2023

What version of Hls.js are you using?

v1.4.6

What browser (including version) are you using?

chrome 111

What OS (including version) are you using?

windows 11

Test stream

No response

Configuration

{}

Additional player setup steps

No response

Checklist

Steps to reproduce

https://stackblitz.com/edit/vitejs-vite-stkzfz?file=src%2FApp.svelte

Expected behaviour

should not error

What actually happened?

Hello, since version 1.4.0 importing isSupported from hls.js/src/is-supported throws an error from vite.

use case:
isSupported function is bundled with my app and hls.js is dynamically imported if media source is supported, so to not increase my app bundle size if hls.js is not needed.

Thanks.

Console output

Missing "./src/is-supported" specifier in "hls.js" package
10:52:43 PM [vite] Internal server error: Missing "./src/is-supported" specifier in "hls.js" package
  Plugin: vite:import-analysis
  File: /home/projects/vitejs-vite-stkzfz/src/App.svelte

Chrome media internals output

No response

@jer-0 jer-0 added Bug Needs Triage If there is a suspected stream issue, apply this label to triage if it is something we should fix. labels Jun 23, 2023
@nostrorom
Copy link

Having the same issue :)

@robwalch
Copy link
Collaborator

The src directory is not part of the distributed package files. isSupported is a static method on the default export, so you can just as well do import { isSupported } from 'hls.js' without any error.

@robwalch robwalch added Works as expected and removed Bug Needs Triage If there is a suspected stream issue, apply this label to triage if it is something we should fix. labels Jul 17, 2023
@jer-0
Copy link
Contributor Author

jer-0 commented Jul 20, 2023

The src directory is not part of the distributed package files. isSupported is a static method on the default export, so you can just as well do import { isSupported } from 'hls.js' without any error.

That doesn't work

Module '"hls.js"' has no exported member 'isSupported'. Did you mean to use 'import isSupported from "hls.js"' instead?

I believe what you mean is this:

import Hls from 'hls.js'
const { isSupported } = Hls

@robwalch
Copy link
Collaborator

I believe what you mean is this:

import Hls from 'hls.js'
const { isSupported } = Hls

Correct, 1.4 defines "hls.js" as an ESM module with a default export of the Hls class.

@robwalch
Copy link
Collaborator

We're also stuck on #5685 for the similar reasons. Users are trying to perform imports on src modules not exported by the project. The project only exports Hls by default for JavaScript and all the types exposed by the API for TypeScript.

@jer-0
Copy link
Contributor Author

jer-0 commented Jul 21, 2023

I argue that isSupported should be re exported because static methods aren't tree shakable by bundlers.

@robwalch
Copy link
Collaborator

I argue that isSupported should be re exported because static methods aren't tree shakable by bundlers.

That would be a breaking change for users that call Hls.isSupported.

We could consider a feature request to remove static methods and provide named exports in v2. That could work for users pulling in the ESM build, but might require changes for folks pulling in the es5 UMD build.

@jer-0
Copy link
Contributor Author

jer-0 commented Jul 21, 2023

I argue that isSupported should be re exported because static methods aren't tree shakable by bundlers.

That would be a breaking change for users that call Hls.isSupported.

not necessarily, isSupported can just be exported from src/hls.ts. No need to remove it as a static method.

export { isSupported }

@robwalch
Copy link
Collaborator

isSupported can just be exported from src/hls.ts.

That's what we wanted to do in #5685, but can not because Hls is the default export.

[!] Error: Entry module "src/hls.ts" is using named and default exports together. Consumers of your bundle will have to use `Hls.default` to access the default export, which may not be what you want. Use `output.exports: "named"` to disable this warning

@robwalch
Copy link
Collaborator

With #5930 we export all enums and classes on the public API. If you'd like static functions on the API (Hls) to be exported independently of the API, please open an PR that adds the named export.

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

Successfully merging a pull request may close this issue.

3 participants