{"id":19274,"library":"babel-preset-env-modules","title":"babel-preset-env-modules","description":"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.","status":"active","version":"1.0.1","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install babel-preset-env-modules","lang":"bash","label":"npm"},{"cmd":"yarn add babel-preset-env-modules","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-preset-env-modules","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"core preset for compiling JS","package":"@babel/preset-env","optional":false},{"reason":"polyfill plugin used for finer grained core-js polyfills","package":"babel-polyfill-corejs3","optional":false}],"imports":[{"note":"This is a Babel preset, used in .babelrc or babel.config.js, not imported in application code.","wrong":"import preset from 'babel-preset-env-modules'","symbol":"babel-preset-env-modules","correct":"module.exports = { presets: [['babel-preset-env-modules', options]] }"},{"note":"Presets are strings in Babel config, not require() calls.","wrong":"module.exports = { presets: [require('babel-preset-env-modules')] }","symbol":"DEFAULT","correct":"module.exports = { presets: ['babel-preset-env-modules'] }"}],"quickstart":{"code":"// babel.config.js\nmodule.exports = {\n  presets: [\n    [\n      'babel-preset-env-modules',\n      {\n        targets: { esmodules: true },\n        loose: true,\n        bugfixes: true,\n        modules: false, // preserve ESM\n        polyfill: {\n          // see babel-polyfill-corejs3 options\n          corejs: 3,\n          proposals: true,\n        },\n      },\n    ],\n  ],\n};","lang":"javascript","description":"Configure Babel with babel-preset-env-modules for ESM targets with polyfill support."},"warnings":[{"fix":"Use polyfill option instead of manually setting corejs/useBuiltIns in preset-env options.","message":"The polyfill option automatically sets corejs and useBuiltIns, overriding any manual settings passed to preset-env.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Consider migrating to direct use of @babel/preset-env with useBuiltIns: 'usage' and corejs option.","message":"The package is essentially a wrapper that may become obsolete as @babel/preset-env and babel-polyfills improve.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Ensure polyfill option is configured to respect modules setting.","message":"Setting modules to false (preserve ESM) may conflict with polyfill plugin if not careful; polyfill may still inject non-ESM code.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"npm install babel-preset-env-modules --save-dev","cause":"Preset not installed","error":"Error: [BABEL] unknown preset 'babel-preset-env-modules'"},{"fix":"npm install @babel/preset-env --save-dev","cause":"Missing @babel/preset-env peer dependency","error":"TypeError: Cannot read property 'preset-env' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}