invariant icon indicating copy to clipboard operation
invariant copied to clipboard

Support ES Modules

Open appsforartists opened this issue 7 years ago • 0 comments

invariant only provides a CommonJS interface (exports = function()). Unfortunately, this will fail if it is used in an ES Module environment (for instance, in jsxstyle).

I don't know enough about how you mirror/bundle this package to provide a PR. A hacky (but probably functional) solution could be to create a default property on invariant and set it to the function:

function invariant() {}
module.exports = invariant;
invariant.default = invariant;

That would allow invariant to be used as an ES Module:

import invariant from 'invariant';

However, a proper ES Module would allow tools like webpack to better optimize bundle size.

appsforartists avatar Nov 02 '17 21:11 appsforartists