感谢@Sidney的评论,我能够解决这个问题。我实际上在查看node.js选项卡而不是文档中的web选项卡。缺少的元素是一个电话 require('firebase/firestore') 让它可用于 firebase 模块。以下是更正后的设置代码:
require('firebase/firestore')
firebase
const firebase = require('firebase') require('firebase/firestore') // *** this line was missing *** const config = { apiKey: 'long_ugly_string', authDomain: 'my_app_id.firebaseapp.com', databaseURL: 'https://my_app_id.firebaseio.com', projectId: 'my_app_id', } firebase.initializeApp(config) const firestore = firebase.firestore() // rest of code ...