javascriptangularjsrequirejsgrunt-contrib-requirejscornerstone

requirejs not loading the object properly


I am configuring angularjs project dependecies using requirejs

following are the configurations

"cornerstone-core":"emp/cornerstone.min",
"cornerstone-math":"emp/cornerstoneMath.min",
"hammer":"emp/hammer.min",
"properties":"emp/properties"
"clientParameters":"emp/clientParameters"
"cornerstone":"emp/cornerstone"
"cornerstoneMath":"emp/cornerstoneMath"
"cornerstoneTools":"emp/cornerstoneTools"
"cornerstoneWADOImageLoaderCodecs":"emp/cornerstoneWADOImageLoaderCodecs"
"cornerstoneWADOImageWebWorker":"emp/cornerstoneWADOImageWebWorker"
"myApp":"emp/myApp"

Runtime dependencies are,

clientParameters : [ "properties" ],
cornerstoneMath : [ "properties", "clientParameters", "cornerstone-core", "cornerstone-math", "hammerjs" ]
cornerstone : [ "properties", "clientParameters", "cornerstone-core", "cornerstone-math", "hammerjs" ],
cornerstoneTools : [ "properties", "clientParameters", "cornerstone-core", "cornerstone-math", "hammerjs" ],
myApp : [ "properties", "clientParameters", "cornerstone", "cornerstoneMath", "cornerstone-core", "cornerstone-math", "hammerjs" ]

In cornerstone.js I am loading the modules in a following way,

(function webpackUniversalModuleDefinition(root, factory) {
  if(typeof exports === 'object' && typeof module === 'object')
    module.exports = factory();
  else if(typeof define === 'function' && define.amd)
    define("cornerstone", [], factory); // error line
  else if(typeof exports === 'object')
    exports["cornerstone"] = factory(); 
  else
    root["cornerstone"] = factory();
})(this, function() {
return (function(modules) {

I am getting the following error,

myApp.js:2312 Uncaught(in promise) ReferenceError: cornerstone is not defined

at line define("cornerstone", [], factory);
when I am replacing the error line with root["cornerstone"] = factory(); everything is working fine.

[EDIT]
factory method is bootstrapper used in this question: Trying to understand Webpack


Solution

  • Because you are using modules, first you have to import corerstone. With AMD modules it would look something like:

    define(["angular", "cornerstone"], function (angular, cornerstone) {
        ....
    });