Closed Rob-pw closed 9 years ago
This obviously breaks in regular browsers because you don't check if module
exists in the first place. In addition to that, as this module already works in node.js and using the exports
patterns is quite common. If browserify doesn't work that I would suggest opening a bug report there.
@3rd-Eden
What would cause this to break in browsers? I assume you mean this existence check is not sufficient?
if (module && module.exports) {
module.exports = Plates;
}
Further, although using the exports 'pattern' is common, using module.exports in addition is recommended, since exports is a shorthand.
This fix is not specifically for browserify, but enables plates to work in libraries such as browserify.
You patch assumed that module
is always defined. If it not defined your code will throw an Reference error stating that module is not defined
which happens to be the case in browsers.
Setting the value of "exports" alone won't expose required properties, an empty object ({}) will be returned. Browserify expects 'module.exports', this fixes the issue.