最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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>
发布评论

评论列表(0)

  1. 暂无评论