Skip to main content
100%

Babel Interop Defaults might lead to confusion with ES6 Modules and imports/exports

✓ Published0🌍 Public
RRestuta
Last edited Jun 9, 2017
Created on Oct 24, 2015

This example shows how Babel’s default interop behavior can make ES6 module imports behave unexpectedly, producing a value where the spec would yield `undefined`. The code defines `export.js` with a default export object, then in `module-b.js` imports a named `x` via `import {x} from './module-a'`. With default Babel settings, `console.log(x)` outputs `8`, because Babel sets both `module.exports` and `exports["default"]`. The example contrasts this with vanilla ES6, where the import would fail, and shows the explicit double export needed for spec-compliant behavior.

AI-generated description

Similar vizzes