ded/morpheus — Issue #19: Morpheus errors when run as an AMD module with RequireJs
Author: Integralist
Created: 2011-12-01 13:09:40+00:00
State: open

Just to be clear first that Morpheus runs fine with RequireJs (by @jrburke) *before* running a build script.

But after running a build script (e.g. when Morpheus is inserted as a module into a single file along with other modules) the script errors when you try to execute the morpheus function. It simply states that: `morpheus is not a function`?

I managed to get this working though by changing Morpheus' define method to match that of `when.js` (by @briancavalier).

So for example I replaced...

```js
!function (name, definition) {
if (typeof define == 'function') define(definition)
else if (typeof module != 'undefined') module.exports = definition()
else this[name] = definition()
}('morpheus', function () {

// MORPHEUS CODE HERE

})
```

...with this...

```js
(function(define) {
define('morpheus',[], function() {

// MORPHEUS CODE HERE

}); // define
})(typeof define != 'undefined'
// use define for AMD if available
? define
// If no define, look for module to export as a CommonJS module.
// If no define or module, attach to current context.
: typeof module != 'undefined'
? function(deps, factory) { module.exports = factory(); }
: function(deps, factory) { this.when = factory(); }
);
```

Just thought you might want to look at changing this so it's compatible. I would have done a fork/pull request but wasn't sure if I needed to do any unit tests (as it seems the majority of repo admins request you do before submitting). So thought it easier just to flag up the issue in case you were interested.

Kind regards,
Mark