実現したいこと
- Failed to load function definition from source: FirebaseError: There was an error reading functions/package.json:を解決させてFlutter×Firebaseの開発手法の理解を深める。
前提
Flutter×Firebaseを用いたメッセージアプリの開発方法をYoutubeの動画を見ながら学習中です。
ターミナルにてfirebase emulators:startをした際に以下のメッセージが発生しました。
発生している問題・エラーメッセージ
Failed to load function definition from source: FirebaseError: There was an error reading functions/package.json:
該当のソースコード
package.json
1{ 2 "name": "functions", 3 "scripts": { 4 "build": "tsc", 5 "build:watch": "tsc --watch", 6 "serve": "npm run build && firebase emulators:start --only functions", 7 "shell": "npm run build && firebase functions:shell", 8 "start": "npm run shell", 9 "deploy": "firebase deploy --only functions", 10 "logs": "firebase functions:log" 11 12 }, 13 "engines": { 14 "node": "16" 15 }, 16 "main": "lib/index.js", 17 "dependencies": { 18 "firebase-admin": "^10.2.0", 19 "firebase-functions": "^4.2.1" 20 }, 21 "devDependencies": { 22 "typescript": "^4.6.4" 23 }, 24 "private": true 25} 26
出力内容
i emulators: Starting emulators: auth, functions, firestore
⚠ functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: database, hosting, pubsub, storage
✔ functions: Using node@16 from host.
i firestore: Firestore Emulator logging to firestore-debug.log
✔ firestore: Firestore Emulator UI websocket is running on 9150.
i ui: Emulator UI logging to ui-debug.log
i functions: Watching "/Users/usernamei/Flutter/cupertino_chat_app/cupertino_chat_app/functions" for Cloud Functions...
⬢ functions: Failed to load function definition from source: FirebaseError: There was an error reading functions/package.json:
functions/lib/src/index.js does not exist, can't deploy Cloud Functions
┌─────────────────────────────────────────────────────────────┐
│ ✔ All emulators ready! It is now safe to connect your app. │
│ i View Emulator UI at http://127.0.0.1:4000/
試したこと
Failed to load function definition from source: FirebaseError: There was an error reading functions/package.json:を和訳したところ、ソースからの関数定義の読み込みに失敗しました。FirebaseError: functions/package.json を読み込む際にエラーが発生しました。という意味だと判明。functions/lib/src/index.js does not exist, can't deploy Cloud Functionsを和訳したところ、functions/lib/src/index.js が存在しないため、Cloud Functions をデプロイできない。という意味だと判明。functions/lib/src/index.js does not exist, can't deploy Cloud Functionsでググったところ、以下のページにヒット。
https://stackoverflow.com/questions/64960780/functions-lib-functions-src-index-ts-does-not-exist-cant-deploy-cloud-function
上記のページを参考にしてFunctionsフォルダに移動し、npm run-script buildコマンドを実行したものの、
src/index.ts:1:1 - error TS6133: 'functions' is declared but its value is never read.
1 import * as functions from "firebase-functions";
Found 1 error in src/index.ts:1
と返ってきました。20分ほど格闘しましたが、解決に至らなかったので有識者の方にご教示していただきたいです。情報の追記依頼などがあればコメントにお願いします。
補足情報(FW/ツールのバージョンなど)
[✓] Flutter (Channel stable, 3.7.0, on macOS 13.1 22C65
darwin-x64, locale ja-JP)
[✓] Android toolchain - develop for Android devices
(Android SDK version 32.1.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.2)
[✓] VS Code (version 1.75.1)
[✓] Connected device (3 available)
[✓] HTTP Host Availability
参考にしている動画
https://youtu.be/zRRCY9mJNNE
追記
https://qiita.com/SatohJohn/items/dc0783594a215c85a60f
の手順1を見ながらやってみましたが解決に至らずでした。
2023/02/12 追記
typescriptを選択したので、ファイル名package.jsonの16行目"main": "lib/index.js",を"main": "lib/index.ts",に変更するも別ファイルでエラーメッセージ発生。
2023/02/13 追記
帰宅後、自宅ではなく近くのコインランドリーでfirebase emulators:startを実行したところ、Failed to load function definition from source: FirebaseError: There was an error reading functions/package.json:は発生しなかったもののシミュレータの画面は真っ黒になった。
帰宅後、再度firebase emulators:startを実行したところ、Failed to load function definition from source: FirebaseError: There was an error reading functions/package.json:が発生。

あなたの回答
tips
プレビュー