从firebase版本8升级到版本9 compat -服务firestore不可用

fnvucqvd  于 2022-11-17  发布在  其他
关注(0)|答案(1)|浏览(116)

在我的React应用程序中,将firebase从版本8升级到版本9(compat)后,我收到以下错误:

provider.ts:130 Uncaught Error: Service firestore is not available
    at Provider.getImmediate (provider.ts:130:1)
    at La (index.esm2017.js:17277:1)
    at ./src/firebase.js (firebase.js:60:1)
    at __webpack_require__ (bootstrap:784:1)
    at fn (bootstrap:150:1)
    at ./src/views-auth/LoginPage.js (LandingPage.js:208:1)
    at __webpack_require__ (bootstrap:784:1)
    at fn (bootstrap:150:1)
    at ./src/layouts/Auth.js (Admin.js:276:1)
    at __webpack_require__ (bootstrap:784:1)
    at fn (bootstrap:150:1)
    at ./src/index.js (firebase.js:186:1)
    at __webpack_require__ (bootstrap:784:1)
    at fn (bootstrap:150:1)
    at 1 (StudentsPage.js:148:1)
    at __webpack_require__ (bootstrap:784:1)
    at checkDeferredModules (bootstrap:45:1)
    at Array.webpackJsonpCallback [as push] (bootstrap:32:1)
    at main.chunk.js:1:109

下面是firebase导入和firebase应用程序初始化。

进口:

import firebase from "firebase/compat/app";
import "firebase/compat/auth";
import "firebase/compat/firestore";
import "firebase/compat/analytics";
import "firebase/compat/functions";
import "firebase/compat/storage";

Firebase应用程序初始化:

第一次
这是我的package.json

{
  "name": "material-dashboard-pro-react",
  "version": "1.9.0",
  "private": true,
  "dependencies": {
    "@aws-sdk/client-cognito-identity": "^3.154.0",
    "@aws-sdk/client-polly": "^3.154.0",
    "@aws-sdk/credential-provider-cognito-identity": "^3.154.0",
    "@date-io/date-fns": "1.x",
    "@material-ui/core": "^4.11.4",
    "@material-ui/data-grid": "^4.0.0-alpha.31",
    "@material-ui/icons": "4.9.1",
    "@material-ui/lab": "^4.0.0-alpha.57",
    "@material-ui/pickers": "^3.3.10",
    "@stripe/firestore-stripe-payments": "^0.0.6",
    "algoliasearch": "^4.14.2",
    "chartist": "0.10.1",
    "classnames": "2.2.6",
    "compressorjs": "^1.1.1",
    "date-fns": "^2.19.0",
    "detect-browser": "^5.2.0",
    "firebase": "9.12.1",
    "google-classroom-share": "^0.5.6",
    "google-translate": "^3.0.0",
    "history": "4.10.1",
    "http2": "^3.3.7",
    "instantsearch.css": "^7.4.5",
    "lodash": "^4.17.21",
    "material-ui-dropzone": "^3.5.0",
    "moment": "^2.29.1",
    "perfect-scrollbar": "1.5.0",
    "react": "16.13.1",
    "react-beautiful-dnd": "^13.1.0",
    "react-bootstrap-sweetalert": "5.1.9",
    "react-chartist": "0.14.3",
    "react-code-input": "^3.10.0",
    "react-confetti": "^6.0.1",
    "react-datetime": "2.16.3",
    "react-dom": "16.13.1",
    "react-gapi": "^1.0.2",
    "react-google-button": "^0.7.2",
    "react-google-charts": "^4.0.0",
    "react-google-login": "^5.2.2",
    "react-iframe": "^1.8.0",
    "react-instantsearch-hooks-web": "^6.33.0",
    "react-loading": "^2.0.3",
    "react-papaparse": "^3.16.1",
    "react-player": "^2.9.0",
    "react-quill": "^1.3.5",
    "react-redux": "^7.2.2",
    "react-redux-firebase": "^3.10.0",
    "react-rewards": "^1.1.2",
    "react-router-dom": "5.2.0",
    "react-scripts": "3.4.1",
    "react-slick": "^0.29.0",
    "react-sortable-hoc": "^2.0.0",
    "react-speech-recognition": "^3.7.0",
    "react-tagsinput": "3.19.0",
    "react-use-intercom": "^1.5.0",
    "react-voice-recorder": "^2.0.7",
    "redux": "^4.0.5",
    "redux-firestore": "^0.15.0",
    "redux-thunk": "^2.3.0",
    "resize-observer-polyfill": "^1.5.1",
    "sass": "^1.55.0",
    "slick-carousel": "^1.8.1",
    "styled-components": "^5.3.3",
    "unsplash-js": "^7.0.4",
    "uuid": "^8.3.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "deploy": "npm run build",
    "lint:check": "eslint . --ext=js,jsx;  exit 0",
    "lint:fix": "eslint . --ext=js,jsx --fix;  exit 0",
    "install:clean": "rm -rf node_modules/ && rm -rf package-lock.json && npm install && npm start",
    "compile-sass": "node-sass src/assets/scss/material-dashboard-pro-react.scss src/assets/css/material-dashboard-pro-react.css",
    "minify-sass": "node-sass src/assets/scss/material-dashboard-pro-react.scss src/assets/css/material-dashboard-pro-react.min.css --output-style compressed",
    "map-sass": "node-sass src/assets/scss/material-dashboard-pro-react.scss src/assets/css/material-dashboard-pro-react.css --source-map true",
    "analyze": "source-map-explorer 'build/static/js/*.js'"
  },
  "optionalDependencies": {
    "@types/googlemaps": "3.39.6",
    "@types/markerclustererplus": "2.1.33",
    "ajv": "6.12.2",
    "typescript": "3.9.3"
  },
  "devDependencies": {
    "eslint-config-prettier": "6.11.0",
    "eslint-plugin-prettier": "3.1.3",
    "gulp": "4.0.2",
    "gulp-append-prepend": "1.0.8",
    "prettier": "2.0.5"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": []
  }
}

firebase版本从8.2.1升级到9.12.1。我寻找类似的问题,但解决方案不起作用。我尝试更改导入URL并重新安装firebase的v9。

olhwl3o2

olhwl3o21#

将此发布为社区Wiki,以帮助其他将遇到此问题的社区Wiki。
Service firestore is not available错误会发生在较低版本的Firebase上,因为它没有更新的compat库。包管理器有时会在更新库时遇到一些问题,使库停留在旧版本。通过删除或移除现有的已安装库并重新安装最新版本应该是解决方案。在这种情况下,使用了Yarn,将通过执行以下命令解决该问题:
删除Firebase库:

yarn remove firebase

Firebase重新安装:

yarn add firebase

相关问题