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

"Error: Cannot find module 'videojs'" when bundling using ES6/Babel and VideoJS 5 #343

Closed
gpmcadamold opened this issue Dec 15, 2015 · 15 comments

Comments

@gpmcadamold
Copy link

I'm currently trying to compile ES6 using Babel and Browserify. The VideoJS blog post suggests something like this should work:

import videojs from 'video.js';
import 'videojs-youtube';

However I'm getting the following error during bundling:

[00:36:38] Browserify Error { [Error: Cannot find module 'videojs' from '/Users/path/to/my/node_modules/videojs-youtube/dist']

Is the VideoJS YouTube plugin compatible with ES6/Babel in the way suggested by the VideoJS blog post?

@eXon
Copy link
Collaborator

eXon commented Dec 15, 2015

Update to 2.0.6 and it should work fine. The require was on videojs instead of video.js. My bad.

Let me know if it works for you!

@gpmcadamold
Copy link
Author

Fantastic, 2.0.6 resolves this issue for me! Thanks for the hard work on this project and for responding so quickly to my issue report 😄

@Fireworks
Copy link

@eXon Possibly related, but I can't get it to build either using this same import structure:

ERROR in ./~/videojs-youtube/dist/Youtube.js                                                          
Module not found: Error: Cannot resolve module 'videojs' in ...node_m
odules/videojs-youtube/dist                                                                           
 @ ./~/videojs-youtube/dist/Youtube.js 25:4-27:6                                                      

Building with webpack, on 2.0.7

@eXon
Copy link
Collaborator

eXon commented Dec 18, 2015

@Fireworks Are you using RequireJS or CommonJS? I think I forgot to fix it for RequireJS

@Fireworks
Copy link

@eXon Webpack, which can handle CommonJS fine, so not sure where it's getting caught up.

@gpmcadamold
Copy link
Author

I've since moved to webpack and have the same issue now. The reason being it seems that webpack can't find a module named videojs, instead it needs to be named video.js.

@Fireworks Did you ever figure out what was going on here? Is it an issue with videojs-youtube or a webpack configuration issue?

@gpmcadamold gpmcadamold reopened this Jan 3, 2016
@Fireworks
Copy link

@gpmcadam No, I poked around for a bit, but ultimately didn't have time to investigate so I am just using YouTube embedding instead at the moment.

@eXon
Copy link
Collaborator

eXon commented Jan 3, 2016

@gpmcadam Try to upgrade to the last version (remove the node_modules/vjs-youtube folder). It has been fixed in a previous version. Let me know if it works

@nhanb
Copy link

nhanb commented Jan 7, 2016

I'm using Webpack too and can confirm that it doesn't work with [email protected].

My imports:

import videojs from 'video.js';
import 'videojs-youtube';

Error message:

ERROR in ./~/videojs-youtube/dist/Youtube.js
Module not found: Error: Cannot resolve module 'videojs' in /[...]/node_modules/videojs-youtube/dist
 @ ./~/videojs-youtube/dist/Youtube.js 25:4-27:6

@nhanb
Copy link

nhanb commented Jan 8, 2016

So apparently after webpack does its dependency wiring magic, node_modules/videojs-youtube/dist/Youtube.js looks like this:

/*global define, YT*/
(function (root, factory) {
  if(typeof define === 'function' && define.amd) {
    define(['videojs'], function(videojs){
      return (root.Youtube = factory(videojs));
    });
  } else if(typeof module === 'object' && module.exports) {
    module.exports = (root.Youtube = factory(require('video.js')));
  } else {
    root.Youtube = factory(root.videojs);
  }
}(this, function(videojs) { [...] }

So I thought Webpack might be importing videojs-youtube as an AMD module, not a CommonJS one, which explains why it worked in Browserify but not Webpack. So I tried explicitly disabling AMD, and it did import without error:

require('imports?define=>false!videojs-youtube');

UPDATE: Before someone tries using VideoJS with React (like me), note that it's far from trivial and you might want to look elsewhere: videojs/video.js#2006 . I think I'll give up VJS for now.

@eXon
Copy link
Collaborator

eXon commented Feb 3, 2016

This has been fixed in the last revision

@eXon eXon closed this as completed Feb 3, 2016
@OscarYin
Copy link

OscarYin commented Aug 24, 2017

@eXon Hi dude,

The latest version 2.4.0 uses the define(['videojs'], function(){})

I think it should be video.js?

I meet this error again, and update it to video.js manually works for me.

I use 2.0.8 now. So 2.0.8 is the latest release version?

@capaj
Copy link
Contributor

capaj commented Aug 30, 2018

I am still getting this error in 2018. If you end up here like me from your google search, I was able to solve it by adding:

new webpack.ProvidePlugin({
    videojs: 'video.js/dist/video.cjs.js'
  }),

and into resolve.alias:

videojs: 'video.js'

which made my build pass.

@brian-gonzalez
Copy link

Getting this error on Windows. Unix systems seem to work fine.

Updating the resolve.alias property to include videojs: 'video.js' does seem to fix it, however shouldn't the AMD module name be "video.js" and not "videojs"?

GCheung55 added a commit to GCheung55/videojs-youtube that referenced this issue Aug 12, 2020
Additional fix for videojs#343.
Youtube.js defines a module with a dependency on `videojs` when it should be `video.js`.
@GCheung55
Copy link

I'm hoping PR #565 addresses the issue workarounds, like aliasing, aren't necessary.

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

No branches or pull requests

8 participants