General developer forum

Requires js issue : Uncaught Error: No define call for ..

 
Picture of allan elleuch
Requires js issue : Uncaught Error: No define call for ..
 

Hello,

I am having trouble with using requireJS of moodle and a script  with dependencie to the video player called videojs. It work fine outside Moodle but inside Moodle it doesn't work, and it gives the following error : 

Uncaught Error: No define call for videojs


From a renderer.php I called my module with 


$this->page->requires->js( new moodle_url($CFG->wwwroot . '/mod/playlist/videojs/app.js') );


And this is my app.js


 requirejs.config({
    paths: {
      "jsrender": 'js/jsrender',
      "videojs": 'js/video'
    },
    shim: {
      "jsrender":{
         deps: ['jquery'],
         exports:"jsrender"

    },
      "videojs":{
         deps: ['jquery'],
         exports:"videojs"

       }
    }
  });
  define('test', ["videojs"], function(videojs) {
    window.videojs = videojs;
      videojs('my_video').ready(function(){
      console.log("My video is ready!");
      });
  });
 requirejs(["test"]);


I don't understand why videojs is not defined because it should be defined with the requirejs.config and the line "define('test', ["videojs"], function(videojs)" . Thank you for your help smile


 
Average of ratings: -
Picture of Justin Hunt
Re: Requires js issue : Uncaught Error: No define call for ..
Particularly helpful MoodlersPlugin developers

I am not sure if you can do it that way. Though I would be interested if you could make it work. I have never been sure how to shim from within Moodle.

The way you generally do this is to build an AMD module. The docs on that are here: https://docs.moodle.org/dev/Javascript_Modules

I use VideoJS in VideoEasy (  https://moodle.org/plugins/filter_videoeasy ) via an AMD module. But the way that is done is a bit round about because the settings are loaded at runtime.

 
Average of ratings: -
Picture of allan elleuch
Re: Requires js issue : Uncaught Error: No define call for ..
 

Thank you for the AMD module advice ! I will ask on other forums too, we will see if it's possible this way.

 
Average of ratings: -
Picture of allan elleuch
Re: Requires js issue : Uncaught Error: No define call for ..
 

I finally make it work by using browserify to handle dependencies, the good point is that I have a big javascript file that is like a "standalone", the bad point is that I need to use browserify each time I need to modify something. 

 
Average of ratings: -
Picture of Stefan Lehneis
Re: Requires js issue : Uncaught Error: No define call for ..
 

Hello Allan,

i have the same problem with the videojs library an requirejs.

How did you resolve the problem?


Tanks a lot

Stefan

 
Average of ratings: -