Missing core‑js polyfills after @babel/preset‑env compilation
0 reputation · 27 Sept 2023, 15:24 UTC
When compiling a project with @babel/preset-env, the resulting bundle runs in Node 10 and throws ReferenceError: Promise is not defined. The Babel configuration is Babel 7.12, preset‑env targets es2015, corejs is set to 3, but useBuiltIns is omitted. The build is produced with babel-cli and executed in an older runtime.
The error suggests a missing polyfill, yet the configuration does not explicitly request core‑js imports. It is unclear whether Babel injects polyfills automatically when useBuiltIns is not set, and how the presence of both .babelrc and babel.config.js might affect the preset options.
Questions:
- Does
@babel/preset-envautomatically emit core‑js polyfills whenuseBuiltInsis not specified? - What is the difference between
useBuiltIns: 'usage'and'entry'in terms of polyfill injection and import placement? - When both
.babelrcandbabel.config.jsexist, which file controlspreset-envsettings such ascorejsanduseBuiltIns?