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

Support importing Plyr in Node.js without errors #960

Merged
merged 1 commit into from
May 14, 2018
Merged

Support importing Plyr in Node.js without errors #960

merged 1 commit into from
May 14, 2018

Conversation

friday
Copy link
Collaborator

@friday friday commented May 14, 2018

This injects a type check for navigator before the module header, so it's only run if the environment is a browser. If not (if it's Node.js) then no errors will be thrown, but the imported module will just be an empty object literal. For browsers it won't have any effect.

I think this should fix the SSR issue (#935).

The advantage to this is that it's just a small change and the regression risk is minimal. Alternative solutions would require wrapping the main module (not possible with import and export statements to begin with since they need to be at the top level) or wrapping supports.js, defaults.captions.language and utils.getBrowser() separately, as well as remembering to add this type check to new methods in the future.

The detection will fail if you define navigator globally in Node.js, as some jsdom users might do to actually support other front end libraries (not just imoprting them) in Node.js, but I don't think we should bother supporting this use case.

@sampotts sampotts merged commit 797b709 into sampotts:master May 14, 2018
@friday friday deleted the 935 branch May 14, 2018 16:45
filips123 pushed a commit to filips123/plyr that referenced this pull request Nov 22, 2018
Support importing Plyr in Node.js without errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants