2019年5月19日日曜日

firebase-toolsをバージョンアップすると動かない

firebase-toolsをバージョンアップするとNuxtで作成したSSRアプリがfirebase serveで動かなくなったので、その対処法を記録しておきます。
結論としては「最新バージョンでは動かない」ということになります。

環境

Windows10
Node.js v8.15.0
Nuxt.js v2.7.1

検証にはcreate-nuxt-appでなにもモジュールを追加しないプロジェクトを作成して、Firebase Functionsで動作するようにちょっと修正した以下のプロジェクトを使用しました。
https://github.com/TAC/nuxt-ssr-firebase-example

6.9.0

そもそもhostingが起動しません。
6.9.1で修正された模様です。

6.9.1

functions実行時に以下のメッセージが表示されて動きません。

!  The Cloud Functions emulator requires the module "firebase-admin" to be installed as a dependency. To fix this, run "npm install --save firebase-admin" in your functions directory.
i  functions: Your functions could not be parsed due to an issue with your node_modules (see above)

使ってないのにfirebase-adminを要求されます。
とりあえずdevDependenciesに追加して、再度実行すると以下のエラーに変わります。

!  The Cloud Functions emulator requires the module "firebase-admin" to be installed. This package is in your package.json, but it's not available. You probably need to run "npm install" in your functions directory.
i  functions: Your functions could not be parsed due to an issue with your node_modules (see above)

これは6.9.2で修正されたようです。

6.9.2

今度はfirebase-functions-testを要求されるようになります。

!  The Cloud Functions emulator requires the module "firebase-functions-test" to be installed as a development dependency. To fix this, run "npm install --save-dev firebase-functions-test" in your functions directory.
i  functions: Your functions could not be parsed due to an issue with your node_modules (see above)

メッセージ通りdevDependenciesに追加して再実行すると、以下のエラーメッセージが表示される。

!  The Firebase Admin module has not been initialized early enough. Make sure you run "admin.initializeApp()" outside of any function and at the top of your code

使ってないのだが初期化が必要になっています。
これは6.10.0で修正されたようです。

6.10.0

6.10.0でいろいろ修正されていたので、起動できるようになっているかと期待したが、以下のエラーが解消できませんでした。
以前は、モジュールの読み込み等でNuxtが起動できていなくて同様のエラーが出ていたが、そうではないようです。

>  C:\work\repos\nuxt\example\functions\index.js:19
>        promise.then(resolve).catch(reject)
>                ^
>
>  TypeError: Cannot read property 'then' of undefined
>      at Immediate.nuxt.render.promise [as _onImmediate] (C:\work\repos\nuxt\example\functions\index.js:19:15)
>      at runCallback (timers.js:812:20)
>      at tryOnImmediate (timers.js:768:5)
>      at processImmediate [as _immediateCallback] (timers.js:745:5)

6.9.0以降はまともに動かなくなってしまった。

6.8.0

今のところちゃんと動く最新バージョンは6.8.0です。
このバージョンあたりからNode.js v6が非推奨になったので、--ignore-enginesのオプションをつけないと@google-cloud/functions-emulatorのインストールに失敗します。

https://github.com/googlearchive/cloud-functions-emulator/issues/267

yarn global add firebase-tools@6.8.0 @google-cloud/functions-emulator --ignore-engines

まだ、しばらくは6.8.0を使っていくしかないようです。

追記(2019-05-21)

解決しました!
詳細は下記の記事に記載してあります。
https://blog.28go.jp/2019/05/firebase-tools-v6100-nuxtssr.html

Written with StackEdit.

firebase-tools v6.10.0 release note 和訳

※翻訳勉強中のため、間違っている可能性があります。


https://github.com/firebase/firebase-tools/releases/tag/v6.10.0

  • database:instances:{create,list} now allow viewing and creating Realtime Database instances
  • Fixed issue with CORS rejecting some callable functions
  • Functions emulator no longer watches node_modules files
  • Functions emulator fails to route HTTPS functions to user-provided Express app
  • Functions emulator fails to provide correct req.path
  • Functions emulator fails on various malformed body requests
  • Functions emulator fails on Windows with EACCESS error
  • Functions emulator can now automatically initialize firebase-admin for simple use-cases
  • Fixed race condition where downloading emulators would sometimes resolve too early and fail
  • Fixed a number of issues that broke functions:shell
  • Fixed an issue where Firestore emulator would not start if rules file can’t be found

  • database:instances:{create,list} コマンドで Realtime Database インスタンスの表示と作成が可能になりました
  • 一部の呼び出し可能関数を拒否したCORSに関する問題を修正しました
  • 関数エミュレータは node_modules ファイルを監視しなくなりました
  • 機能エミュレータがHTTPS機能をユーザー提供のExpressアプリにルーティングできない
  • 関数エミュレータが正しい req.path を提供できない
  • 関数エミュレータがさまざまな不正な形式の本体要求で失敗する
  • Windows上でEACCESSエラーで関数エミュレータが失敗する
  • 関数エミュレータは単純なユースケースのためにfirebase-adminを自動的に初期化するようになりました
  • エミュレータをダウンロードすると早く解決しすぎて失敗することがあるという競合状態を修正しました
  • functions:shellを壊したいくつかの問題を修正しました
  • ルールファイルが見つからないとFirestoreエミュレータが起動しない問題を修正しました

Written with StackEdit.

2010年5月13日木曜日

jQueryである要素のイベントをすべて表示する方法

とりあえずどんなイベントが起こってるのかを見たい時に。

var arr = ["blur", "focus", "focusin", "focusout", "load",
           "resize", "scroll", "unload", "click", "dblclick",
           "mousedown", "mouseup", "mousemove", "mouseover",
           "mouseout", "mouseenter", "mouseleave", "change",
           "select", "submit", "keydown", "keypress", "keyup",
           "error"];
$.each(arr, function() {
  var type = this+"";
  $("option").bind(type, function(event) {
    $("pre[id='debug']").append(event.type + ":"
                                + event.target.nodeName
                                + "<br>");
  });
  $("select").bind(type, function(event) {
    $("pre[id='debug']").append(event.type + ":"
                                + event.target.nodeName
                                + "<br>");
 });
});