首页 > 解决方案 > ReferenceError:找不到变量:React 上的 regeneratorRuntime

问题描述

我正在尝试使用 react 和 firebase 创建登录。我一直在关注一个教程,问题是这段代码:

const handleLogin = useCallback(
    async event => {
        event.preventDefault();
        const { email, password } = event.target.elements;
        try {
            await firebaseConfig.auth().signInWithEmailAndPassword(email.value, password.value);
            history.push("/citas")
        } catch (error) {
            alert(error);
        }
    },
    [history]
);

给我这个错误:

ReferenceError:找不到变量:regeneratorRuntime

我没有找到任何解决方案,因为我不知道这意味着什么。有任何想法吗?

标签: reactjsfirebase

解决方案


使用 @babel/polyfill 已被正式弃用。由于您使用的是 react 应用程序(并且不依赖于遗留代码库),您可能更喜欢使用以下内容:

npm i --save core-js/stable regenerator-runtime
// ECMA Script Polyfills:
import "core-js/stable";
// Needed for the generator functions which are transpiled from your async await keywords
import "regenerator-runtime/runtime";

参考


推荐阅读