【问题标题】:Vue.js and ES7: ReferenceError: RegeneratorRuntime not definedVue.js 和 ES7:ReferenceError:RegeneratorRuntime 未定义
【发布时间】:2023-04-06 13:11:01
【问题描述】:

我想在我的 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 现在已将其添加到导入中: 导入“再生器运行时”;

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

【问题讨论】:

    标签: node.js vue.js npm async-await babeljs


    【解决方案1】:

    我通过安装 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
    

    我希望这会很有用。 问候。

    【讨论】:

    • 这个解决方案对我帮助很大,非常感谢:)
    猜你喜欢
    • 2019-04-27
    • 2020-08-28
    • 2016-10-29
    • 2018-05-28
    • 2018-09-19
    • 2019-02-23
    • 2019-10-09
    • 1970-01-01
    • 2017-11-13
    相关资源
    最近更新 更多