enhanced-require icon indicating copy to clipboard operation
enhanced-require copied to clipboard

Amd module with return doesn't get populated on node.js

Open bitplanets opened this issue 10 years ago • 1 comments

A module like this will return {}

define(function(require, exports, module){

    var logic = {
        a: 3
    }
    return logic;
});

Here is the index.js

var myRequire2 = require('enhanced-require')(module);
console.log(myRequire2('./test'))

This will output {} instead of {logic: 3}. Why is this happening and how to fix it?

I can't change all the define(function(require, exports, module){ files to make them work with module.exports = logic. (The module.exports works ok)

On the client side with webpack works perfectly fine.

Thanks

bitplanets avatar Dec 03 '14 17:12 bitplanets

Here https://github.com/webpack/enhanced-require/blob/master/lib/RequireContext.js#L344 instead of:

fn(reqFn, parent.exports, parent);

should be

parent.exports = fn(reqFn, parent.exports, parent);

Or something more specific, like only replacing if no value is set in parent.exports.

bitplanets avatar Dec 03 '14 17:12 bitplanets