gpt4 book ai didi

firebase - 捆绑失败 : SyntaxError: Unexpected end of JSON input in react native

转载 作者:行者123 更新时间:2023-12-01 05:50:42 26 4
gpt4 key购买 nike

我正在使用 火力基地在我的 react 原生项目 .当我尝试使用电子邮件和密码注册用户时,此错误即将来临。
我正在使用 窗口操作系统 并且只有 andorid 渲染

注:我已经阅读了与此相关的所有问题,但没有任何帮助

新手对 native 作出 react 。请以适当的方式指导

package.json

"firebase": "^5.8.2",
"native-base": "^2.11.0",
"react": "16.6.3",
"react-native": "^0.57.8",
"react-native-elements": "^0.19.1",
"react-native-firebase": "^5.2.2",
"react-native-gesture-handler": "^1.0.15",
"react-native-maps": "^0.23.0",
"react-native-svg": "^8.0.10",
"react-native-vector-icons": "^6.2.0",
"react-navigation": "^3.2.1"

注册码
import * as firebase from 'firebase'

//Intiazlize firebase
const firebaseConfig = {
apiKey: "AIzaSyCUK5QkcvTcvfCKlbwnnI8GskIgcLGMcqA",
authDomain: "trailertracker-da09c.firebaseapp.com",
databaseURL: "https://trailertracker-da09c.firebaseio.com",
projectId: "trailertracker-da09c",
storageBucket: "",
}


firebase.initializeApp(firebaseConfig)

signUpUser = (email,password) => {
try{
if(this.state.password.length < 6 ){
alert("Please Enter Valid Email and Password")
return
}

firebase.auth().createUserWithEmailAndPassword(email,password)

} catch(err){
console.log(err)
}
}

完全错误是

Loading dependency graph, done. error: bundling failed: SyntaxError: Unexpected end of JSON input at JSON.parse () at FileStore.get (F:\React Native\ReactProjects\trailer-tracker\TrailerTracker\node_modules\metro-cache\src\stores\FileStore.js:26:19) at F:\React Native\ReactProjects\trailer-tracker\TrailerTracker\node_modules\metro-cache\src\Cache.js:76:40 at Generator.next () at step (F:\React Native\ReactProjects\trailer-tracker\TrailerTracker\node_modules\metro-cache\src\Cache.js:18:30) at F:\React Native\ReactProjects\trailer-tracker\TrailerTracker\node_modules\metro-cache\src\Cache.js:37:14 at new Promise () at F:\React Native\ReactProjects\trailer-tracker\TrailerTracker\node_modules\metro-cache\src\Cache.js:15:12 at Cache.get (F:\React Native\ReactProjects\trailer-tracker\TrailerTracker\node_modules\metro-cache\src\Cache.js:102:7) at F:\React Native\ReactProjects\trailer-tracker\TrailerTracker\node_modules\metro\src\DeltaBundler\Transformer.js:166:34 BUNDLE [android, dev] ....../index.js 68.2% (947/1147), failed.



这是 firebase 中的另一个错误或错误吗?

帮助将不胜感激

谢谢

最佳答案

在 React Native 中开始使用 firebase。

添加 Firebase 依赖项

yarn add firebase

Goto Firebase and make a new project and going to the section Add Firebase to your web app



像这样创建一个用于配置 Firebase 的类
import firebase from "@firebase/app";
require("firebase/database");
require("firebase/storage");
require("firebase/auth");

let config = {
apiKey: "YOUR PROJECT apiKey",
authDomain: "YOUR PROJECT authDomain",
databaseURL: "YOUR PROJECT databaseURL",
projectId: "XXXXXXXX",
storageBucket: "",
messagingSenderId: "XXXXXXXXXX",
appId: "XXXXXXXXXXXXXXXXXXXXXXXX"
};

export default class DBHandler {
static auth;
static database;

static init() {
firebase.initializeApp(config);
DBHandler.database = firebase.database();
DBHandler.auth = firebase.auth();
}
}

App.js 初始化 Firebase
import DBHanlder from "./src/api/constants";

export default class App extends Component {
componentDidMount = () => {

DBHanlder.init();
};

render() {
return <YourApp />;
}
}

Your're done with initialization part .now you can use for auth like below


import DBHandler from "../api/constants";
class Login extends Component {

signinUser = () => {
DBHandler.auth.signInWithEmailAndPassword(email, password)
.then(() => {
//Do what you want
})
.catch((error) => {
//handle error
var errorCode = error.code;
var errorMessage = error.message;
alert(errorMessage);
console.log("ERROR");
console.log(errorCode, errorMessage);
});
}
}}

关于firebase - 捆绑失败 : SyntaxError: Unexpected end of JSON input in react native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54679965/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com