-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Importing VideoJS as ES6 module not working properly. #2698
Comments
Huh? We are doing exactly that already for quite some time and it still seems to work: /**
* @file related-content.js
*/
import videojs from 'video.js';
import * as utils from '../../utils.js';
const VjsComponent = videojs.getComponent('Component');
[...] This works correctly for us. We use browserify + babelify (just like video.js) and we can succesfully compile and run this code. |
The main issue comes with whether you import videojs directly or not. If you add videojs as a global and then try to import it via browserify-shim, it will fail because babel will either export things as es6-modules or commonjs but not both. I have some more detailed notes on this that I'll post later today. |
See babel/babel#2047 and babel/babel#2212 and http://babeljs.io/docs/usage/modules/#interop |
Some background on babel's interop: https://stackoverflow.com/questions/33505992/babel-6-changes-how-it-exports-default/33506169#33506169 |
Check out https://www.npmjs.com/package/babel-plugin-add-module-exports when updating to babel 6.x. |
I think what we probably should do is not use ES6 export at all for the main module export. |
This also applies to projects like contrib-hls and all the other projects we're using browserify with. |
this is my code |
I believe this is fixed now and doing |
I keep getting an error on this line
Anybody know why this might be happening? I'm importing it in my react component like this:
where the |
I noticed today that importing VideoJS and attempting to access properties on it (e.g.,
import videojs from 'video.js'; videojs.getComponent('Foo');
) throws an undefined property error.After investigating with @gkatsev, it appears this is caused by the way
videojs
is being exported in thevideo.js
source file. Becausevideojs
is thedefault
export, accessing properties of it (as above) ultimately gets transpiled to something like_videoJs2['default'].getComponent('Foo')
.The most direct solution is to have
videojs['default'] = videojs;
.The text was updated successfully, but these errors were encountered: