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

3
我想在我的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";

我成功地运行了npm安装。此外,我的main.js现在已经添加了以下导入内容:

import 'regenerator-runtime';

我可以构建项目,但仍然无法使用regeneratorRuntime运行时,我仍然得到相同的referenceError错误。我还需要做些什么或者我错过了什么?

1个回答

7

我通过安装 core-jsregenerator-runtime 解决了我的问题。

npm i -S core-js@latest regenerator-runtime@latest

然后在你的主文件中导入它,在我的例子中是 main.js,因为它在 Webpack 的 entry 键中声明。

// 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

希望这对你有用。 问候。


这个解决方案帮了我很多,非常感谢 :) - Rigin Oommen

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接