persvr / perstore

CommonJS persistence/object storage based on W3C's object store API.
http://www.persvr.org/
96 stars 20 forks source link

Running under Node.js with AMD fails #36

Closed kitsonk closed 12 years ago

kitsonk commented 12 years ago

It appears that some modules attempt to detect AMD, but if they do, the fail to return properly when trying to require() in modules.

Using Dojo's dojo/node module to require in perstore like the following:

define([
  "dojo/node!perstore/stores",
  "dojo/node!perstore/model"
], function(stores, model){
  // ...
});

Will return the following output:

/node_modules/perstore/errors.js:2
var AccessError = exports.AccessError = ErrorConstructor("AccessError");
                                        ^
TypeError: undefined is not a function
    at Object.<anonymous> (/Users/kitsonk/github/dote/node_modules/perstore/errors.js:2:41)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at Object.<anonymous> (/Users/kitsonk/github/dote/node_modules/perstore/facet.js:7:21)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)

Because there is a globally defined define() the util/extend-error.js fails to export the properly for the calling code, which is not AMD aware.

kitsonk commented 12 years ago

Actually, looking further into this, it would be better for the dojo/node AMD pluggin to descope define before attempting to require in the modules.