Vue3.js) Error: Module 'firebase' not found
P粉928591383
P粉928591383 2024-03-31 19:01:32
0
1
333

My first time using firebase with vue.js. After installing firebase using npm, I added it to main.js as shown below.

//main.js
import { createApp } from "vue";
import App from "./App.vue";
import Router from "./router.js";
// bootstrap
import "bootstrap/dist/css/bootstrap.min.css";
import "bootstrap";

// firebase
import firebase from "firebase";

// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
  apiKey: "",
  authDomain: "",
  projectId: "",
  storageBucket: "",
  messagingSenderId: "",
  appId: "",
  measurementId: "",
};

firebase.initializeApp(firebaseConfig);

createApp(App).use(Router).mount("#app");

This is package.json

"dependencies": {
    "bootstrap": "^5.1.3",
    "core-js": "^3.6.5",
    "firebase": "^9.6.4",
    "vue": "^3.0.0",
    "vue-carousel-card": "^2.0.0",
    "vue-router": "^4.0.12",
    "vue3-carousel": "^0.1.35"
  },

If I add firebase and run the service like this, it prints an error saying firebase cannot be found.

This dependency was not found:

* firebase in ./src/main.js

To install it, you can run: npm install --save firebase

Could you please tell me the cause and solution of this problem? Thank you forever.

P粉928591383
P粉928591383

reply all(1)
P粉004287665

You are using "firebase": "^9.6.4", which uses a different import method.

You can downgrade to Firebase 8:

npm remove firebase
npm add firebase@^8.10.0

But if you want to use firebase 9, you can use

import firebase from 'firebase/compat/app' //v9

firebase.initializeApp({
   ...
})

or

import { initializeApp } from 'firebase/app';

initializeApp({
  ...
})
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!