Vue.js 和 ES7:ReferenceError:RegeneratorRuntime 未定义

Nar*_*tor 3 node.js npm async-await vue.js babeljs

我想在我的 vue 应用程序中使用 async/await 语法。这样做时,我收到此错误:ReferenceError:regeneratorRuntime未定义

我已经在 github 上找到了指向用户 adi518 这个方向的多个解决方案: https://github.com/adi518/vue-facebook-login-component/issues/17

就语法而言,我可能会在 main.js 的顶部尝试这个,因为就责任而言,这就是您通常初始化库和 polyfill 的地方(App.vue 似乎不相关)。

So,

npm install --save regenerator-runtime
And then:

import "regenerator-runtime";
Run Code Online (Sandbox Code Playgroud)

我成功运行了 npm 安装。另外,我的 main.js 现在已将其添加到导入中: import 'regenerator-runtime';

我可以构建项目,但运行时 regeneratorRuntime 仍然不起作用,我得到相同的引用错误。我还能做什么或者我错过了什么?

Die*_*sch 7

core-js我通过安装解决了我的问题regenerator-runtime

npm i -S core-js@latest regenerator-runtime@latest
Run Code Online (Sandbox Code Playgroud)

然后在主文件的开头导入它,在我的例子中,main.js因为它是在entryWebpack 的密钥上声明的。

// Recomendation of babeljs (https://babeljs.io/docs/en/babel-polyfill)
import 'core-js/stable'; // only stable feature also is possible with only `core-js`
import 'regenerator-runtime/runtime'; // To ensure that regeneratorRuntime is defined globally
Run Code Online (Sandbox Code Playgroud)

我希望这会有用。问候。