Does @babel/preset-env preserve ES modules when modules is auto?
0 reputation · 26 Apr 2021, 09:37 UTC
Goal: Determine whether @babel/preset-env with modules set to "auto" preserves ES import/export syntax or converts it to CommonJS in a given build pipeline.
Constraint: Babel 7.x defaults modules to "auto", which defers the module transform decision to the calling tool. The Babel CLI may resolve auto to CommonJS, while Rollup or webpack configured for ES modules may leave import/export statements intact for tree-shaking. Identical .babelrc or babel.config.json can therefore emit different syntax depending on the integration.
Uncertainty: Without knowing which caller resolves the option, it is unclear whether a shared configuration produces stable module output across CLI and bundler workflows.
Which caller controls the final module syntax when modules is "auto"? Can the same preset config safely target both Babel CLI and an ESM-aware bundler without explicit modules overrides? What output should be expected when no bundler caller is present?