Skip to content

kingback/babel-plugin-mix-import-module-exports

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

babel-plugin-mix-import-module-exports

Why we use it

When mixed use import and module.exports:

import A from 'a';
// ...
module.exports = A

it will lead to problems with bundling like this:

TypeError: Cannot assign to read only property 'exports' of object '#<Object>'

For more infomation, see these issues:

almende/vis#2934

webpack/webpack#4039 (comment)

webpack/webpack#3491

https://stackoverflow.com/questions/42449999/webpack-import-module-exports-in-the-same-module-caused-error

How it works

This plugin makes things work by transforming the code into:

var __MIX_IMPORT_MODULE_EXPORTS__;
import A from 'a';
// ...
__MIX_IMPORT_MODULE_EXPORTS__ = A;
export default __MIX_IMPORT_MODULE_EXPORTS__;

or sometimes maybe we have multiple module.exports in our module:

var __MIX_IMPORT_MODULE_EXPORTS__;
import A from 'a';
import B from 'b';
// ...
if (B) {
  __MIX_IMPORT_MODULE_EXPORTS__ = B;
} else {
  __MIX_IMPORT_MODULE_EXPORTS__ = A;
}
export default __MIX_IMPORT_MODULE_EXPORTS__;

Important Note

This plugin is just for compatibility with old projects, you should not use it in your new projects.

About

Fix mixed use ES6 imports and Common.js exports

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published