はじめまして。
Vue.jsで簡単なチャットを作っているのですが、firebaseのDatabaseにpushしようとすると以下のエラーが出ますので、こちらを解決するにはどうしたらよいか教えていただきたいです。
Failed to compile.
./node_modules/firebase/dist/index.cjs.js
Module build failed: Error: ENOENT: no such file or directory, open '/Users/xxx/Sites/vue_chat/vue-chat/node_modules/firebase/dist/index.cjs.js'
@ ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/App.vue 12:0-32
@ ./src/App.vue
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js
コードは以下になります。
html
1<!DOCTYPE html> 2<html> 3 <head> 4 <meta charset="utf-8"> 5 <meta name="viewport" content="width=device-width,initial-scale=1.0"> 6 <title>vue-chat</title> 7 8 <script src="https://www.gstatic.com/firebasejs/6.2.1/firebase-app.js"></script> 9 <script> 10 // Your web app's Firebase configuration 11 var firebaseConfig = { 12 apiKey: "xxx", 13 authDomain: "xxx", 14 databaseURL: "xxx", 15 projectId: "xxx", 16 storageBucket: "xxx", 17 messagingSenderId: "xxx", 18 appId: "xxx" 19 }; 20 // Initialize Firebase 21 firebase.initializeApp(firebaseConfig); 22 </script> 23 </head> 24 <body> 25 <div id="app"></div> 26 </body> 27</html> 28
vue
1<template> 2 <div id="app"> 3 <p v-for="m in messages">{{ m }}</p> 4 <input type="text" ref="msg"> 5 <button @click="send">送信</button> 6 </div> 7 8</template> 9 10<script> 11 12import firebase from 'firebase' 13 14export default { 15 name: 'app', 16 data () { 17 return { 18 messages: [], 19 }; 20 }, 21 methods: { 22 send: function() { 23 this.messages.push(this.$refs.msg.value); 24 firebase.database().ref('messages').push({ 25 message: this.$refs.msg.value, 26 }); 27 } 28 } 29}; 30</script> 31 32<style> 33</style> 34
import firebase from 'firebase'
こちらを記述することで、上記エラーが発生します。
解決方法を調べてはいましたがどれも理解できず試せておりません。
環境
・MacOS
・Vue 3.8.4
・firebase 7.0.0
他に解決に必要な情報があればそちらも教えていただきたいです。
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。