質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Vue.js

Vue.jsは、Webアプリケーションのインターフェースを構築するためのオープンソースJavaScriptフレームワークです。

Firebase

Firebaseは、Googleが提供するBasSサービスの一つ。リアルタイム通知可能、並びにアクセス制御ができるオブジェクトデータベース機能を備えます。さらに認証機能、アプリケーションのログ解析機能などの利用も可能です。

Q&A

0回答

629閲覧

[Vue.js]Firebaseの利用時にターミナルでエラー文が表示される

DKI

総合スコア11

Vue.js

Vue.jsは、Webアプリケーションのインターフェースを構築するためのオープンソースJavaScriptフレームワークです。

Firebase

Firebaseは、Googleが提供するBasSサービスの一つ。リアルタイム通知可能、並びにアクセス制御ができるオブジェクトデータベース機能を備えます。さらに認証機能、アプリケーションのログ解析機能などの利用も可能です。

0グッド

0クリップ

投稿2022/01/12 12:45

編集2022/01/14 13:39

https://www.youtube.com/watch?v=_n67scuq4QQ&t=166s

こちらの動画を参考にして、VueとFirebaseでTodoアプリを作成中にその31の02:00くらいの時の

javascript

1import firebase from 'firebase' 2 3this.db = firebase.firestore()

などを入力した後にエラーが表示されました。

ターミナルのエラー文

npm --version
8.1.0

npm run serve

ERROR Failed to compile with 2 errors 21:34:06 This dependency was not found: * firebase in ./src/main.js, ./node_modules/cache-loader/dist/cjs.js??ref--13-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--1-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/HelloWorld.vue?vue&type=script&lang=js& To install it, you can run: npm install --save firebase

コード全文

javascript

1app.vue 2 3<template> 4 <div class="hello"> 5 <h1>{{ msg }}</h1> 6 7 <h1>TODO</h1> 8 9 <div> 10 <input v-model="NewTodoName"/> 11 <button @click="addTodo()">追加</button> 12 </div> 13 14 <ul> 15 <li> 16 <input type="checkbox"> 17 タスク名 18 </li> 19 <button>X</button> 20 </ul> 21 22 </div> 23</template> 24 25<script> 26import firebase from 'firebase' 27 28export default { 29 name: 'HelloWorld', 30 props: { 31 msg: String 32 }, 33 34 data(){ 35 return { 36 db: null, 37 todosRef: null, 38 NewTodoName:'' 39 } 40 }, 41 42 created(){ 43 this.db = firebase.firestore() 44 this.todosRef = this.db.collection("todos") 45 }, 46 47 methods: { 48 addTodo(){ 49 if(this.NewTodoName === ''){ return } 50 this.todosRef.add({ 51 name: this.NewTodoName, 52 isComplete: false 53 }) 54 } 55 } 56} 57</script> 58 59<!-- Add "scoped" attribute to limit CSS to this component only --> 60<style scoped> 61h3 { 62 margin: 40px 0 0; 63} 64ul { 65 list-style-type: none; 66 padding: 0; 67} 68li { 69 display: inline-block; 70 margin: 0 10px; 71} 72a { 73 color: #42b983; 74} 75</style> 76

javascript

1main.js 2 3import Vue from 'vue' 4import App from './App.vue' 5 6 7 8// Import the functions you need from the SDKs you need 9import { initializeApp } from "firebase/app"; 10// TODO: Add SDKs for Firebase products that you want to use 11// https://firebase.google.com/docs/web/setup#available-libraries 12 13// Your web app's Firebase configuration 14const firebaseConfig = { 15 apiKey: "$$", 16 authDomain: "$$", 17 projectId: "$$", 18 storageBucket: "$$", 19 messagingSenderId: "$$", 20 appId: "$$" 21}; 22 23// Initialize Firebase 24initializeApp(firebaseConfig); 25 26Vue.config.productionTip = false 27 28new Vue({ 29 render: h => h(App), 30}).$mount('#app') 31

javascript

1pakage.json 2 3{ 4 "name": "firebase", 5 "version": "0.1.0", 6 "private": true, 7 "scripts": { 8 "serve": "vue-cli-service serve", 9 "build": "vue-cli-service build", 10 "lint": "vue-cli-service lint" 11 }, 12 "dependencies": { 13 "core-js": "^3.6.5", 14 "firebase": "^9.6.2", 15 "vue": "^2.6.11" 16 }, 17 "devDependencies": { 18 "@vue/cli-plugin-babel": "~4.5.0", 19 "@vue/cli-plugin-eslint": "~4.5.0", 20 "@vue/cli-service": "~4.5.0", 21 "babel-eslint": "^10.1.0", 22 "eslint": "^6.7.2", 23 "eslint-plugin-vue": "^6.2.2", 24 "vue-template-compiler": "^2.6.11" 25 }, 26 "eslintConfig": { 27 "root": true, 28 "env": { 29 "node": true 30 }, 31 "extends": [ 32 "plugin:vue/essential", 33 "eslint:recommended" 34 ], 35 "parserOptions": { 36 "parser": "babel-eslint" 37 }, 38 "rules": {} 39 }, 40 "browserslist": [ 41 "> 1%", 42 "last 2 versions", 43 "not dead" 44 ] 45} 46 47

試したこと

https://qiita.com/massu159/items/4a08effbff720dfc107c

こちらを参考にver9のimport方法に書き換える

npm install --save firebase

は実行済み

https://firebase.google.com/docs/web/setup

こちらの記事を参考にして、main.jsを

javascript

1import Vue from 'vue' 2import App from './App.vue' 3 4 5 6// Import the functions you need from the SDKs you need 7import { initializeApp } from 'firebase/app'; 8import { getFirestore, collection, getDocs } from 'firebase/firestore/lite'; 9// Follow this pattern to import other Firebase services 10// import { } from 'firebase/<service>'; 11 12// TODO: Add SDKs for Firebase products that you want to use 13// https://firebase.google.com/docs/web/setup#available-libraries 14 15// Your web app's Firebase configuration 16const firebaseConfig = { 17 18}; 19 20// Initialize Firebase 21const app = initializeApp(firebaseConfig); 22const db = getFirestore(app); 23db 24// Get a list of cities from your database 25async function getCities(db) { 26 const citiesCol = collection(db, 'cities'); 27 const citySnapshot = await getDocs(citiesCol); 28 const cityList = citySnapshot.docs.map(doc => doc.data()); 29 return cityList; 30} 31 32export default {getCities}; 33 34Vue.config.productionTip = false 35 36new Vue({ 37 render: h => h(App), 38}).$mount('#app') 39

ともしてみましたが、うまく行きません。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

DKI

2022/01/13 06:22

npm add firebase npm install --save firebase も試しましたが、同じエラー文が表示されてしまいます
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問