Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/456.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase(Firestore)Javascript不断显示错误_Javascript_Firebase_Google Cloud Firestore - Fatal编程技术网

Firebase(Firestore)Javascript不断显示错误

Firebase(Firestore)Javascript不断显示错误,javascript,firebase,google-cloud-firestore,Javascript,Firebase,Google Cloud Firestore,被困了好几天了。 代码是从google firebase文档中复制的 我只想在firebase控制台中的firestore上写和读数据。 Firebase(Firestore)Javascript不断显示错误 有人能帮我写代码吗?我不需要花哨的代码或任何东西。只要从firestore读写就可以了 <!DOCTYPE html> <html> <head> <script src="https://www.gstatic.com/fireba

被困了好几天了。 代码是从google firebase文档中复制的

我只想在firebase控制台中的firestore上写和读数据。 Firebase(Firestore)Javascript不断显示错误

有人能帮我写代码吗?我不需要花哨的代码或任何东西。只要从firestore读写就可以了

<!DOCTYPE html>
<html>
<head>
  <script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-firestore.js"></script>


</head>
<body>
  <script>
    // Firebase App (the core Firebase SDK) is always required and must be listed first
import firebase from "firebase/app";
// If you are using v7 or any earlier version of the JS SDK, you should import firebase using namespace import
// import * as firebase from "firebase/app"

// If you enabled Analytics in your project, add the Firebase SDK for Analytics
import "firebase/analytics";

// Add the Firebase products that you want to use
import "firebase/auth";
import "firebase/firestore";

// TODO: Replace the following with your app's Firebase project configuration
// For Firebase JavaScript SDK v7.20.0 and later, `measurementId` is an optional field
const firebaseConfig = {
    apiKey: "******",
    authDomain: "retest-5308a.firebaseapp.com",
    databaseURL: "https://retest-5308a-default-rtdb.firebaseio.com",
    projectId: "retest-5308a",
    storageBucket: "retest-5308a.appspot.com",
    messagingSenderId: "125780245080",
    appId: "1:125780245080:web:530259dc2a4b1362aae82d",
    measurementId: "G-PNTZS15X9K"
  };
  
  // Initialize Firebase
  firebase.initializeApp(firebaseConfig);

const firebase = require("firebase");
// Required for side-effects
require("firebase/firestore");

// Initialize Cloud Firestore through Firebase
firebase.initializeApp({
    apiKey: "********",
    authDomain: "retest-5308a.firebaseapp.com",
    projectId: "retest-5308a"
  });
  
  var db = firebase.firestore();

  db.collection("users").add({
    first: "Ada",
    last: "Lovelace",
    born: 1815
})
.then((docRef) => {
    console.log("Document written with ID: ", docRef.id);
})
.catch((error) => {
    console.error("Error adding document: ", error);
});
  </script>
</body>

</html>

//Firebase应用程序(核心Firebase SDK)始终是必需的,必须首先列出
从“firebase/app”导入firebase;
//如果您使用的是v7或任何早期版本的JS SDK,则应使用名称空间导入导入firebase
//从“firebase/app”导入*作为firebase
//如果在项目中启用了分析功能,请添加Firebase SDK进行分析
导入“firebase/analytics”;
//添加要使用的Firebase产品
导入“firebase/auth”;
导入“firebase/firestore”;
//TODO:将以下内容替换为应用程序的Firebase项目配置
//对于Firebase JavaScript SDK v7.20.0及更高版本,`measurementId`是可选字段
常量firebaseConfig={
apiKey:“*******”,
authDomain:“重新测试-5308a.firebaseapp.com”,
数据库URL:“https://retest-5308a-default-rtdb.firebaseio.com",
Projectd:“重新测试-5308a”,
storageBucket:“重新测试-5308a.appspot.com”,
messagingSenderId:“125780245080”,
appId:“1:125780245080:web:530259dc2a4b1362aae82d”,
测量结果:“G-PNTZS15X9K”
};
//初始化Firebase
firebase.initializeApp(firebaseConfig);
const firebase=require(“firebase”);
//副作用所需
要求(“消防基地/消防仓库”);
//通过Firebase初始化云Firestore
firebase.initializeApp({
apiKey:“*******”,
authDomain:“重新测试-5308a.firebaseapp.com”,
项目:“重新测试-5308a”
});
var db=firebase.firestore();
数据库集合(“用户”)。添加({
第一个:“Ada”,
最后一句:“Lovelace”,
出生:1815
})
。然后((docRef)=>{
console.log(“使用ID编写的文档:”,docRef.ID);
})
.catch((错误)=>{
console.error(“添加文档时出错:”,错误);
});

您不能使用
从“firebase/app”导入firebase脚本
标记内的code>

相反,您应该通过它们自己的
脚本
标记导入这些SDK,就像您已经为
firebase firestore.js所做的那样


一旦您通过
script
标记添加SDK,就不再需要
imports

您是否可以至少发布错误?似乎存在多个问题。当我修复了其中一些错误时,错误会从其他地方突然出现。请查看此URL。重新测试-5308a.firebaseapp.com非常感谢。我删除了导入和require,它工作得非常好。