webpacker: regeneratorRuntime is not defined

Seems to be similar to https://github.com/rails/webpacker/issues/517

screen shot 2017-06-19 at 07 31 41

webpacker 2.0.0 node 8.0.0

.babelrc

{
  "presets": [
    ["env", {
      "modules": false,
      "targets": {
        "node": "current",
        "browsers": "> 1%",
        "uglify": true
      },
      "useBuiltIns": true
    }]
  ],

  "plugins": [
    "syntax-dynamic-import",
    ["transform-class-properties", { "spec": true }]
  ]
}

package.json

{
  "name": "dirtylemon-admin",
  "private": true,
  "dependencies": {
    "autoprefixer": "^7.1.1",
    "axios": "^0.16.1",
    "babel-core": "^6.25.0",
    "babel-loader": "7.x",
    "babel-plugin-syntax-dynamic-import": "^6.18.0",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-polyfill": "^6.23.0",
    "babel-preset-env": "^1.5.2",
    "babel-preset-react": "^6.24.1",
    "bootstrap": "4.0.0-alpha.6",
    "coffee-loader": "^0.7.3",
    "coffee-script": "^1.12.6",
    "compression-webpack-plugin": "^0.4.0",
    "css-loader": "^0.28.4",
    "extract-text-webpack-plugin": "^2.1.2",
    "file-loader": "^0.11.2",
    "glob": "^7.1.2",
    "immutability-helper": "^2.2.0",
    "jquery": "^3.2.1",
    "js-yaml": "^3.8.4",
    "lodash": "^4.17.4",
    "moment": "^2.18.1",
    "moment-timezone": "^0.5.13",
    "node-sass": "^4.5.3",
    "notie": "^4.3.0",
    "numeral": "^2.0.6",
    "path-complete-extname": "^0.1.0",
    "postcss-loader": "^2.0.6",
    "postcss-smart-import": "^0.7.4",
    "precss": "^1.4.0",
    "rails-erb-loader": "^5.0.2",
    "react": "^15.5.4",
    "react-auto-scroll": "^1.1.0",
    "react-dom": "^15.5.4",
    "react-redux": "^5.0.5",
    "redux": "^3.6.0",
    "redux-saga": "^0.15.3",
    "redux-thunk": "^2.2.0",
    "resolve-url-loader": "^2.0.3",
    "sass-loader": "^6.0.6",
    "style-loader": "^0.18.2",
    "tablesort": "^5.0.0",
    "webpack": "^2.6.1",
    "webpack-manifest-plugin": "^1.1.0",
    "webpack-merge": "^4.1.0"
  },
  "devDependencies": {
    "webpack-dev-server": "^2.4.5"
  }
}

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 45 (19 by maintainers)

Commits related to this issue

Most upvoted comments

Here is my solution (reference: https://github.com/rails/webpacker/blob/master/docs/es6.md):

  1. Add @babel/polyfill:
yarn add -D @babel/polyfill
  1. Add import "@babel/polyfill" into your front-end app’s entry file (eg. app/javascript/packs/application.js)
import "@babel/polyfill";

Done!

Ok, I re run rails webpacker:install:react and it works. I’ll also update .babelrc just in case

There is a tricky part with @f6v solution. Installing the new uglifyjs-webpack-plugin package works, but you need to replace Webpacker’s default UglifyJs plugin with it. Here is how:

// config/webpack/environment.js
const { environment } = require('@rails/webpacker');
const UglifyPlugin = require('uglifyjs-webpack-plugin');

// Replace Uglify plugin with the new one.
environment.plugins.set('UglifyJs', new UglifyPlugin());

@gauravtiwari when I remove

"browsers": "> 1%", "uglify": true

and replace with "node": "current" it works fine in development mode but fails to deploy to heroku. Any ideas why?

Don’t forget to also set useBuiltIns: 'entry' in your .babelrc (defaults to false)

Also note:

NOTE: Only use require("@babel/polyfill"); once in your whole app. Multiple imports or requires of @babel/polyfill will throw an error since it can cause global collisions and other issues that are hard to trace. We recommend creating a single entry file that only contains the require statement.

So, make sure that if you use @babel/polyfill in multiple entry files (/packs/*.js), don’t load multiple entry files on a single page. If you find yourself needing to do this, consider using dynamic import to include the different files.

@f6v You may wanna use https://babeljs.io/blog/2016/08/30/babili instead, remove uglify and replace it with babili

@gauravtiwari I did, see my .babelrc