Registry / devops / babel-preset-env-modules

babel-preset-env-modules

JSON →
library1.0.1jsnpmunverified

A Babel preset that wraps @babel/preset-env and babel-polyfill-corejs3 to produce minimal compiled output for environments that support ESM, with improved polyfill handling. Current version 1.0.1, released as a single stable version. It solves the common issue where preset-env conflates helpers and polyfills, leading to unnecessary code. Key differentiators: automatically prevents inclusion of supported builtins, uses finer-grained polyfills via babel-polyfills, excludes niche polyfills (e.g., Symbol.species) by default, and coordinates options between preset-env and polyfill plugin to avoid conflicts. Suitable for library authors targeting modern browsers or Node.js with ESM.

npm install babel-preset-env-modules
INSTALL
IMPORT
SIG · BABEL-PRESET-ENV-M
B
babel-preset-env-modules
devopsjavascriptv1.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

babel-preset-env-modules
module.exports = { presets: [['babel-preset-env-modules', options]] }
import preset from 'babel-preset-env-modules'
This is a Babel preset, used in .babelrc or babel.config.js, not imported in application code.
DEFAULT
module.exports = { presets: ['babel-preset-env-modules'] }
module.exports = { presets: [require('babel-preset-env-modules')] }
Presets are strings in Babel config, not require() calls.

Configure Babel with babel-preset-env-modules for ESM targets with polyfill support.

// babel.config.js module.exports = { presets: [ [ 'babel-preset-env-modules', { targets: { esmodules: true }, loose: true, bugfixes: true, modules: false, // preserve ESM polyfill: { // see babel-polyfill-corejs3 options corejs: 3, proposals: true, }, }, ], ], };
Debug
Known issues
gotchaThe polyfill option automatically sets corejs and useBuiltIns, overriding any manual settings passed to preset-env.
fix
Use polyfill option instead of manually setting corejs/useBuiltIns in preset-env options.
affects: >=1.0.0
deprecatedThe package is essentially a wrapper that may become obsolete as @babel/preset-env and babel-polyfills improve.
fix
Consider migrating to direct use of @babel/preset-env with useBuiltIns: 'usage' and corejs option.
affects: >=1.0.0
gotchaSetting modules to false (preserve ESM) may conflict with polyfill plugin if not careful; polyfill may still inject non-ESM code.
fix
Ensure polyfill option is configured to respect modules setting.
affects: >=1.0.0
Errors
Common errors & fixes
Error: [BABEL] unknown preset 'babel-preset-env-modules'
Preset not installed
fix
npm install babel-preset-env-modules --save-dev
TypeError: Cannot read property 'preset-env' of undefined
Missing @babel/preset-env peer dependency
fix
npm install @babel/preset-env --save-dev
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
@babel/preset-envrequiredcore preset for compiling JS
babel-polyfill-corejs3requiredpolyfill plugin used for finer grained core-js polyfills
Agent activity
2 hits · last 30 days
node
2
Resources
babel-preset-env-modules — npm install babel-preset-env-modules · libregistry