LoginSignup
4
1

More than 3 years have passed since last update.

Cloud Functions for Firebaseの導入で躓いたこと

Last updated at Posted at 2019-07-10

注意

自分用のメモとしての意味合いが強いので、簡単に記載しています。
前提として、Firebase CLIなどのインストールは済んでいるものとします。

事象

firebase init functionsHTTP Error: 401, Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential.で失敗する

https://stackoverflow.com/a/52891586 を参考に、一度firebase logoutでログアウトしてからfirebase loginでログインし直したところ解決しました。

firebase deploy --only functionsError: An unexpected error has occurred.と表示されて失敗する

https://stackoverflow.com/a/56885970 を参考にnpm install -g npm@6.9.2を実行することで解決しました。

firebase deploy --only functionsが成功してもFirebaseコンソールに反映されない

最初に生成されたサンプルコードをそのままデプロイしていたのが原因でした。

index.js
const functions = require('firebase-functions');

// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions
//
// exports.helloWorld = functions.https.onRequest((request, response) => {
//  response.send("Hello from Firebase!");
// });

コメントアウトを外したら反映されました。

index.js
const functions = require('firebase-functions');

// Create and Deploy Your First Cloud Functions
// https://firebase.google.com/docs/functions/write-firebase-functions

exports.helloWorld = functions.https.onRequest((request, response) => {
  response.send("Hello from Firebase!");
});
4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1