5

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

  • 2
    Can you show us your factory function? `define("cornerstone", [], factory);` cannot throw `ReferenceError: cornerstone is not defined`. It looks one of your modules is depending on a global variable called `cornerstone`, which is not present when a module loader is used. – Tamas Hegedus Mar 11 '18 at 19:52
  • cornerstone variable is part of cornerstone.js and everything is working fine when I am using `root["cornerstone"]=factory()` –  Mar 11 '18 at 19:54
  • 2
    Can you show me the 2312nd line if myApp.js? – Tamas Hegedus Mar 11 '18 at 21:37
  • Updated the question. it is not breaking in myApp.js, it is breaking in cornerstone.js while accessing the cornerstone object –  Mar 13 '18 at 13:44
  • 1
    I did check cornerstone.js, it's distribution version doesn't reference itself (https://github.com/cornerstonejs/cornerstone/blob/master/dist/cornerstone.js) That still means you have some code referencing cornerstone without importing it properly – Tamas Hegedus Mar 13 '18 at 18:00
  • 1
    So to be clear: the line `define("cornerstone", [], factory)` cannot throw the error `Uncaught(in promise) ReferenceError: cornerstone is not defined`, because it is not referencing `cornerstone` at all. We will have to look into the `factory` function, and walk down the stacktrace a littlebit. – Tamas Hegedus Mar 13 '18 at 18:04
  • 1
    Can you paste full error object? – Shreyance Jain Mar 19 '18 at 11:23
  • @TamasHegedus you are right, it is breaking in one of my file i.e `myApp.js` at `image = cornerstone.renderGrayscaleImage;` In chrome Dev I have added a watch on `cornerstone` variable and its state is `undefined` –  Mar 20 '18 at 11:31
  • Have you tried adding `var cornerstone = require('cornerstone');` somewhere in `myApp.js`? – Tamas Hegedus Mar 20 '18 at 21:55

1 Answers1

0

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) {
    ....
});
Tamas Hegedus
  • 24,663
  • 9
  • 48
  • 87