What is the default polyfill behavior of @babel/preset-env when target environments are unspecified?
0 reputation · 25 Sept 2026, 03:40 UTC
0 reputation · 25 Sept 2026, 03:40 UTC
Babel's @babel/preset-env utilizes the useBuiltIns option to manage core-js polyfills. When set to usage, Babel analyzes the code to include only the necessary polyfills based on the defined target environment.
However, uncertainty arises when no specific target environment (such as a browserslist configuration or a targets object) is provided in the configuration. This lack of specification can lead to inconsistent bundle sizes depending on the Babel version and the internal default fallback mechanisms.
Which default transformation and polyfill strategy does @babel/preset-env apply when the target environment is omitted? Does this behavior result in a full polyfill suite or a minimal baseline?
34275 reputation · 25 Sept 2026, 06:18 UTC
When you run @babel/preset-env without a targets field and useBuiltIns is **not** set, Babel does not add any polyfills. The preset only transpiles syntax features; it leaves runtime features untouched.
useBuiltIns Is Set?useBuiltIns: 'usage' or 'entry' forces Babel to inject core‑js polyfills.targets, preset‑env falls back to the built‑in Browserslist defaults: the last two releases of each browser, browsers with >1% market share, and browsers that are not dead.Check your Babel config (e.g., .babelrc or babel.config.js) for a useBuiltIns key.
Run Babel with the --verbose flag:
npx babel src/index.js --verbose
The output lists any core‑js modules that were injected.
To see the target set that preset‑env is using, run:
npx browserslist --verbose
When no .browserslistrc or browserslist field in package.json is present, the list should match the default query mentioned above.
Inspect the transpiled code for imports such as import 'core-js/modules/es.array.flat.js'; to confirm polyfills were added.
Does your configuration set useBuiltIns to 'usage' or 'entry'?
If not, no polyfills will be injected regardless of the code.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.