简体   繁体   English

Vue3.js )错误:找不到模块'firebase'

[英]Vue3.js ) Error: Cannot find module 'firebase'

I'm using firebase for the first time in vue.js. After installing firebase using npm, I added it to main.js as follows.我在vue.js中第一次使用firebase。使用npm安装firebase后,我将其添加到main.js中,如下所示。

//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");

And this is package.json这是 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 serve it like this, an error that says firebase cannot be found is output.如果我添加 firebase 并像这样运行服务,则显示找不到 firebase 的错误是 output。

This dependency was not found:

* firebase in ./src/main.js

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

May I know the cause and solution of this?可以知道这是什么原因和解决方法吗? Thank you always.永远谢谢你。

You are using "firebase": "^9.6.4" which uses different way of importing.您正在使用 "firebase": "^9.6.4" ,它使用不同的导入方式。

You can downgrade to firebase 8:可以降级为firebase 8:

npm remove firebase
npm add firebase@^8.10.0

But if you want to use firebase 9 you can either use但是如果你想使用 firebase 9 你可以使用

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

firebase.initializeApp({
   ...
})

or或者

import { initializeApp } from 'firebase/app';

initializeApp({
  ...
})

I've got the same issue, and I found a solution: change your firebase version, it'll work.我遇到了同样的问题,我找到了解决方案:更改您的 firebase 版本,它会工作。

npm remove firebase
npm add firebase@^8.10.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 FIrebase 部署错误:找不到模块“firebase-admin” - FIrebase deploy error: Cannot find module 'firebase-admin' 初始化“@nuxtjs/firebase”模块时出现 Nuxt 致命错误 - 找不到模块“firebase/compat/app” - Nuxt FATAL error when initializing '@nuxtjs/firebase' module - Cannot find module 'firebase/compat/app' 部署 firebase 项目时出现错误显示“找不到模块 firebase-functions” - Error shows 'cannot find module firebase-functions' when deploying a firebase project 错误:运行时出现“找不到模块” firebase 云 function - Error: "Cannot find module" while running firebase cloud function 出现错误:找不到模块“js-yaml” - Getting Error: Cannot find module 'js-yaml' 找不到模块“firebase-functions” - cannot find module "firebase-functions" 注册时出现 POST 400 错误 - Vue JS / Firebase - POST 400 error on signup - Vue JS / Firebase 无法使用 firebase 在 vue 中发布/注册错误 - Cannot POST/ register error in vue using firebase 未捕获的错误:尝试在 firestore 中使用 serverTimestamp 时找不到模块“firebase” - Uncaught Error: Cannot find module 'firebase' when trying to use serverTimestamp in firestore 错误:在谷歌应用引擎上部署 node.js 后找不到模块“/workspace/server.js” - Error: Cannot find module '/workspace/server.js' upon node js deploy on google app engine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM