enhanced-require
enhanced-require copied to clipboard
Amd module with return doesn't get populated on node.js
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
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.