Open kay-ws opened 4 years ago
コード見た感じでは特に問題なさそうですね 🤔 念の為に確認させていただきたいのですが、dotenv のインストール後はサーバーの再起動はしてますかね?nuxt が nuxt.config.js を上手く読み込めていなければ、上のようなエラーが出るかもなーと思ったので。
https://github.com/kay-ws/SlackCloneApp/blob/master/nuxt.config.js
※noteに章番号のほか、節(+項)番号を付けていただけると、どのあたりまでというのが提示しやすいのですが(例:1-2-1まで)。ご検討いただきたく。
たしかにこれは不便ですね... 🙇 改善します!ご指摘ありがとうございます!
ことの発端は1通のメールです。(全文コピー)
Firebase の場合、無料プランがあるので不正に利用されて高額請求が来るということはないので、基本大丈夫なのですが、これ心配になりますよね...
JavaScriptに記載されているので、基本公開されますしね... https://stackoverflow.com/questions/37482366/is-it-safe-to-expose-firebase-apikey-to-the-public
GitHub で公開する場合を想定して、dotenv 使うように note を変更しようかなとちょっと思いました。
・サーバの再起動というのが、「npm run dev」を止めて起動しなおすことであれば、実行しています。 (Ctrl+Cでプロセスを止めて再度「npm run dev」) ・nodeを入れなおすといいというサイトもあったので、「sudo yum remove nodejs」「sudo yum install nodejs」を実行しましたがエラーは消えず。 ・fsオブジェクトが無効なのか調べるために以下のコマンドを実行 a.js
var fs = require('fs');
var message = fs.readFileSync(__dirname + '/message.txt');
console.log(message);
message.txt
message
コマンド
node a.js
message.txtのファイルの中身が出力されれば有効。エラーなら無効。
<Buffer 6d 65 73 73 61 67 65>
あれ、fsオブジェクト生きてますね。???
今日いっぱい調べてみてわからなかったら開発環境再構築してみます。
サーバの再起動というのが、「npm run dev」を止めて起動しなおすことであれば、実行しています
なるほど!
fsオブジェクト生きてますね。
生きているっぽいですね。 ということは nuxt 環境で build する際に上手く読み込めていないっぽいですね。ちょっと調べてみます。
これ通りにやったら直ったりしないですかね? https://github.com/nuxt-community/dotenv-module/issues/11#issuecomment-412322241
情報ありがとうございます。
// nuxt.config.js
export default {
...
build: {
...
extend: function (config, {isDev, isClient}) {
config.node = {
fs: "empty"
};
}
},
...
};
これを実施したところエラーが出なくなり、 「npm run dev」が実行できるようになりました。
どうもありがとうございました。
おお、解決してよかったです!!!
たびたび失礼します。
①聞きたいことの一行まとめ dotenvを導入すると「This dependency was not found:* fs in ./node_modules/dotenv/lib/main.js」となって実行できなくなる。
②起きている問題(起きている現象の詳細/エラーメッセージ/スクリーンショット) ことの発端は1通のメールです。(全文コピー)
GitGuardianというところからの警告で、Google APIキーをGithub上で世界中に晒しているということのようでした。
早速、firebaseのDatabaseを一度消し、再度作り直ししました。 (これでapiKey類が変わったのでとりあえず良いかと思い)
次に、以下のコマンドでdotenvをインストールしました。
npm install --save dotenv
そしてプロジェクトフォルダ直下に.devファイルを作り API類のデータをそこに記載しました。そしてplugins/firebase.jsを以下のような記述に書き換えました。
これで対策できたと思い、npm run devをしたところ
とエラーが出てしまい動きません。 ③ソースコード(関連するソースコード/全ソースコード) https://github.com/kay-ws/SlackCloneApp.git
④問題解決するために試したこと(コードもあれば追記) エラーメッセージの指示通りに 「npm install --save fs」をして再度「npm run dev」をしてみました。 →結果変わらず。 ⑤問題について自分なりに考えたこと(デバッグ結果/検索結果/自分なりの原因予想)
⑥当該コンテンツを購入したnoteのアカウント Note ID: kay_ws ニックネーム:けい
⑦noteのどのあたりまでやったのか メッセージの保存と表示 の前まで。
※noteに章番号のほか、節(+項)番号を付けていただけると、どのあたりまでというのが提示しやすいのですが(例:1-2-1まで)。ご検討いただきたく。