Palaniichuk Dmytro
Palaniichuk Dmytro

Reputation: 3173

Babel 7 and babel-polyfill

After updating to babel 7 beta, looks like babel polyfill does not transpile before bundle. I updated all scoped packages like this one "@babel/polyfill": "7.0.0-beta.36". And changed imports for two files from import 'babel-polyfill' to import '@babel/polyfill'. How to use babel/pollyfill with babel env and babel 7. Should I use babel/polyfill when use useBuiltIns: 'usage', with targets?

.babelrc.js

const nodeEnv = process.env.NODE_ENV || 'development'
let presetEnvConfig, plugins

if (nodeEnv === 'test'){
    presetEnvConfig = {targets: {node: 'current'}}
    plugins = ['istanbul']
} else {
    presetEnvConfig = {
        targets: {
            browsers: ['last 2 versions', 'ie >= 11']
        },
        modules: false
    }
    plugins = ['react-hot-loader/babel']
}

const config = {
    presets: [
        ['@babel/preset-env', presetEnvConfig],
        '@babel/react',
        '@babel/stage-2'
    ],
    plugins,
}

types.js

import keyMirror from '../../../utils/keyMirror'

export default keyMirror({
    Unassign: null,
    Reassign: null,
    QuickAssignment: null,
}, 'TagAssignmentTypes')

index.js

 <Assignment
     assignee={assignee}
     tagId={tagId && tagId.toString(16)}
     assignmentType={assignmentTypes.Reassign}
     onRequestClose={() => this.setState({isAssignmentInProgress: false})}
     onChange={onChange}
    />

Upvotes: 2

Views: 3639

Answers (3)

user8532998
user8532998

Reputation: 21

The following worked for me, add 
**.babelrc**
{
"presets": [
  ["@babel/env"]
]
}

**app.js**
import "core-js/stable";
import "regenerator-runtime/runtime";

*Install as pointed by gianmarco*
npm i --save core-js regenerator-runtime

Upvotes: 0

gianmarco
gianmarco

Reputation: 31

@babel/polyfill is a wrapper package which only includes imports of stable core-js features (in Babel 6 it also included proposals) and regenerator-runtime/runtime, needed by transpiled generators and async functions. This package doesn't make it possible to provide a smooth migration path from core-js@2 to core-js@3: for this reason, it was decided to deprecate @babel/polyfill in favor of separate inclusion of required parts of core-js and regenerator-runtime.

Instead of

import "@babel/polyfill";

you should use those 2 lines:

import "core-js/stable";
import "regenerator-runtime/runtime";

Don't forget install those dependencies directly!

npm i --save core-js regenerator-runtime

enter image description here

Upvotes: 2

Raja Sekar
Raja Sekar

Reputation: 2130

Change

@babel/stage-2 to @babel/preset-stage-2

Upvotes: 0

Related Questions