Questions tagged [babel-preset-env]

73 questions
3
votes
1 answer

How to use babel's env preset to target Node with ES6 modules enabled?

With this config: { "presets": [ [ "@babel/preset-env", { "targets": { "node": "16" } } ] ] } ...Babel converts import/export syntax to CommonJS (require). How do I change this so Babel…
callum
  • 34,206
  • 35
  • 106
  • 163
3
votes
2 answers

Why does using babel preset-env with `useBuiltIns: "usage"` cause an error in harmony-module?

I am attempting to configure babel preset-env to take care of injecting polyfills automatically, with respect to the specified list of target browsers. The documentation states that configuring the preset-env preset with a property in the form of…
kohloth
  • 742
  • 1
  • 7
  • 21
3
votes
0 answers

Unexpected empty lines when transpiling JavaScript with Babel 7.2.2 and preset-env

I am getting various unexpected empty lines when I transpile a JavaScript snippet with Babel. Here is the source code: /** * Header. */ function header() { const header = 'header'; console.log(header); }; /** * Navigation. */ function…
Dmitry Mayorov
  • 216
  • 2
  • 9
3
votes
0 answers

How does babel-preset-env handle polyfill loading

As performance is always important I was wondering how to best include polyfills. I'd prefer to use codesplitting and then lazyload each polyfill if the current environment doesn't that support it. Doing this manually requires more work which I…
danielreiser
  • 5,292
  • 5
  • 31
  • 43
2
votes
0 answers

Vite don't transpile code with Babel plugin

I'm trying to convert default Vite template JS with Babel/preset-env, to be compatible with older browsers - to es2015. In code generated by Vite still appear const instead of var. I'm using this plugin -…
M-Zoldak
  • 46
  • 6
2
votes
0 answers

Module parse failed: The keyword 'interface' is reserved | Babel loader

I had a project set up and I am using Babel loader to compile both js and tsx files. While compiling I am facing following errors like Module parse failed: The keyword 'interface' is reserved (1:15) You may need an appropriate loader to handle this…
2
votes
0 answers

Why does a pollyfilled component need to be polyfilled in imported project again?

I've a React component that I've created as a library. I've run the build for it with webpack and babeljs. In the babel.config.js of the Babel for this component library, I had the following to polyfill functions that may not exist in older…
Carven
  • 14,988
  • 29
  • 118
  • 161
2
votes
2 answers

Async / Await using babel regenerator-runtime does not work in ie11

I have a template app that I want to make work with ie11, for that I'm using webpack + babel. For some reason I ignore, my JS does not work at all in ie11 even though I did set it as a target in my config. To test it, I use a ie11 on the internet…
2
votes
1 answer

How to generate a browserslist scope to match feature support?

I want to transpile a service worker source file so that it will work on browsers that support service workers. I can't use browserslist directly, because the scope does not accept a list of features to support. Caniuse can tell me which browsers…
JoeTidee
  • 24,754
  • 25
  • 104
  • 149
2
votes
2 answers

Getting default implementation of @babel/present-env to work with IE11

My @babel/preset-env configuration is working fine except for IE11. When I run it in IE11 I get this error: SCRIPT438: Object doesn't support property or method 'assign' After googling the error I see I need to use babel/polyfill, but it is…
MSOACC
  • 3,074
  • 2
  • 29
  • 50
2
votes
1 answer

How to compile TypeScript classes with @babel/preset-typescript?

I'm trying to compile a library of TypeScript classes to ES5 by using a combination of @babel/preset-typescript and @babel/env. Without any plugins, it leads to a compilation error: SyntaxError: C:\projects\time\git\core\main\src\LocalDate.ts:…
Egor Nepomnyaschih
  • 932
  • 1
  • 8
  • 13
2
votes
0 answers

How to list applied transformed for a specified set of targets for babel-preset-env?

We're using babel-preset-env and a specified set of browser versions as targets so that only the needed transforms are applied. We would like to keep this set of versions inline with the versions that are supported by the vendors while staying as…
Dave Johansen
  • 889
  • 1
  • 7
  • 23
2
votes
0 answers

Using babel / browserslist to give *not* supported fallback messages

Is there any hook or plugin that one can use as part of the Babel-verse (e.g., @babel/preset-env, using a plugin of Rollup with browserslist, as a hook within core-js, etc.) which will detect lack of support for the targeted features or lack of…
Brett Zamir
  • 14,034
  • 6
  • 54
  • 77
2
votes
1 answer

Defining multiple babel preset configurations in webpack config

I have created a webpack.config.js file that is exporting two different WebPack configuration objects. I need to set up different babel options for presets within these . After a bit of research I have tried creating two different loader configs,…
ChrisM
  • 1,565
  • 14
  • 24
2
votes
2 answers

Unable to run a node.js file with @babel/preset-env

I'm trying to run a simple node.js file which needs the @babel/preset-env preset. The moment I run the js file, I get a message saying Requires Babel “7.0.0-0” but was loaded with “6.26.3” To replicate the issue, please try the following in a new…
Arun
  • 3,036
  • 3
  • 35
  • 57