2016-06-27 13 views
4

私のプロジェクトでは、browserify + gulp + babelを使用していますが、ES7機能に問題があります。これらは私がインストールされて何をしている:babel ES7 Async - regeneratorRuntimeが定義されていません

、これは私のグッコードである:

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}`)); 
}); 

これは私のjsコードです:

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')); 

私はこれをしようとすると、エラーを取得:を使用して

Uncaught ReferenceError: regeneratorRuntime is not defined

はどちらか動作しませんの代わりインポートする必要があります。ほとんどの質問はWebpackを使用しています。ブラウザではなく、他の方法が私には効果がなかったので、どうすればいいのか教えてください。

もう1つの質問があります。ご覧のとおり、babel-preset-es2015とbabel-preset-es2016の両方をインストールしていて、どちらも使用しています。 es2015プラグインを削除しても、引き続きES6機能を使用できますか?また、バベルプリセットステージ0も含まれています。これは実験的なES7機能のためのものです。実際に何をbabel-preset-es2016が得られましたか?

+0

**変換、再生器**プラグインと**変換-非同期機能**、まだ動作しません。 :( – modernator

答えて

2

同じエラーがあり、「babel-plugin-transform-runtime」を使用して修正しました。 これもあなたのために働くことを願っています。私がインストールさ

Babel 6 regeneratorRuntime is not defined with async/await

+0

最新のbabel + asyncプラグイン+ babel-polyfillでこれを解決しました。ありがとうございます。 – modernator

関連する問題