Javid Asgarov
Javid Asgarov

Reputation: 1532

regeneratorRuntime is not defined, Can I fix this with Gulp?

I use Gulp for transpiling ES6, but with generator it gives the error of: "Uncaught ReferenceError: regeneratorRuntime is not defined".

I have found that I need babel-polyfill for this and documentations suggests uses for Node / Browserify / Webpack.

Can't I fix this in Gulp without webpack? I didn't find how. I installd babel-plugin-transform-regenerator and did this in my gulpfile.js:

    gulp.task('scripts', function() {
      return gulp.src('src/js/*.js')
                 .pipe(plumber())
                 .pipe(babel({
                          presets: ['es2015', 'stage-3'],
                          plugins: ["transform-regenerator"]
                      }))
                 .pipe(uglify())
                 .pipe(gulp.dest('src/js/result'))
                 .pipe(browserSync.stream()); 

});

But it didn't help.

Upvotes: 2

Views: 2760

Answers (1)

Max Vorobjev
Max Vorobjev

Reputation: 1233

This plugin still requires regeneratorRuntime. You need to install babel-polyfill and import it explicitly in your JS:

  1. npm install --save-dev babel-polyfill
  2. Copy polyfill to your static scripts folder: cp node_modules/babel-polyfill/dist/polyfill.min.js ./public/js
  3. Add polyfill script to the top of your html head <script src="/public/js/polyfill.min.js"></script>

Upvotes: 8

Related Questions