add-esmodule
Add __esModule property to native ES module objects
Motivation
Much of the javascript ecosystem relies of ES modules having an __esModule
property. However, native ES modules do not have that property. This project is a workaround for that problem.
Installation
npm install --save add-esmodule
yarn add add-esmodule
Usage
import foo from "foo";
import { cloneWithEsModuleProperty } from "add-esmodule";
const fooCompat = cloneWithEsModuleProperty(foo);
foo.__esModule;
fooCompat.__esModule;
Browser compatibility
add-esmodule works in IE 11+
Implementation notes
- Live Bindings for modules are supported (via object getters on the cloned object)
- The cloned module object is frozen
- Symbols, including toString, are properly cloned