Rasim Avcı
Rasim Avcı

Reputation: 1213

Generator Runtime error when added babel-preset-env and babel-preset-stage-2

I had to use babel-preset-env and babel-preset-stage-2 in order to use webpack for a code that includes spread operator. After that I succeed in building my bundle with webpack but this time I get generator runtime error during runtime.

So first I tried to do solution in this page, babel-polyfill but my team did not want me to use it, instead they asked me to use transform-runtime plugin,so I installed it and put it in babelrc file but still getting same generator-runtime error, any idea about that ? What should I do more ?

here is babelrc file

{
  "presets": [
    "env",
    "stage-2",
    "es2015"
  ],
  "plugins": [
    "transform-async-to-generator",
    [
      "transform-runtime",
      {
        "helpers": false,
        "polyfill": false,
        "regenerator": true
      }
    ]
  ]
}

webpack config file

var path = require('path')

module.exports = {
  entry: path.resolve(__dirname, 'partner/index.js'),
  output: {
    path: path.resolve(__dirname, './dist'),
    filename: 'partner_bundle.js'
  },
  target: 'web',
  module: {
    rules: [
      {
        test: /\.js$/, // Check for all js files
        loader: 'babel-loader',
        query: {
          presets: ['babel-preset-env', 'babel-preset-stage-2'].map(
            require.resolve
          )
        },
        exclude: /node_modules\/(?!other-module)/
      }
    ]
  },
  stats: {
    colors: true
  },
  devtool: 'source-map',
  resolve: { symlinks: false }
}

babel and webpack versions in the package.json

"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-stage-0": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",

"webpack": "^4.0.1",
"webpack-cli": "^2.0.9"

Upvotes: 0

Views: 561

Answers (1)

Jay Jordan
Jay Jordan

Reputation: 743

Try using:

{
  "env": {
    "production": {
      "plugins": ["transform-react-constant-elements"]
    }
  }
}

https://babeljs.io/docs/usage/babelrc/

Upvotes: 0

Related Questions