I'm using browserify + gulp + babel in my project, and having problem with ES7 features. These are what I installed:
- babel-plugin-transform-async-to-generator@6.8.0
- babel-plugin-transform-decorators-legacy@1.3.4 // for use decorators
- babel-polyfill@6.9.1
- babel-preset-es2015@6.9.0
- babel-preset-es2016@6.11.0
- babel-preset-stage-0@6.5.0
- babelify@7.3.0
- browserify@13.0.1
- gulp
- gulp-sourcemaps
- vinyl-buffer
- vinyl-source-stream
and this is my gulp code:
gulp.task('build', () => {
let buildPath;
let destPath;
buildPath = `./src`;
destPath = `./dist`;
return browserify(`${buildPath}/app.js`)
.transform(babelify, {
presets: ["es2015", "es2016", "stage-0"],
plugins: ["transform-decorators-legacy", "transform-async-to-generator"]
})
.bundle()
.pipe(source('app.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(`${destPath}`));
});
and this is my js code:
import 'babel-polyfill';
// Async Functions
function wait(t) {
return new Promise((r) => setTimeout(r, t));
}
async function asyncMania() {
console.log('1');
await wait(1000);
console.log('2');
}
asyncMania().then(() => console.log('3'));
When I try this, gets an error:
Uncaught ReferenceError: regeneratorRuntime is not defined
Using require instead of import doesn't work either. Most of questions are using Webpack, not browserify and other approaches were not worked on me, so it will be very appreciate tell me how should I do.
And I have one more question, as you can see, I installed babel-preset-es2015 and babel-preset-es2016 both, and both are using. If I remove es2015 plugin, can I still use ES6 features? And also I included babel-preset-stage-0, and as I know this is for experimental ES7 features. What actually babel-preset-es2016 got?
1条答案
按热度按时间eit6fx6z1#
我有同样的错误,并通过使用“babel-plugin-transform-runtime”修复它。希望这也为您工作。
Babel 6 regeneratorRuntime is not defined with async/await