javascript - regeneratorRuntime is not defined, Can I fix this with Gulp? - Stack Overflow

I use Gulp for transpiling ES6, but with generator it gives the error of: "Uncaught ReferenceError

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.

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.

Share Improve this question asked Dec 9, 2016 at 17:38 Javid AsgarovJavid Asgarov 1,5321 gold badge18 silver badges33 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745155778a4614112.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信