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.

0 件のコメント:
コメントを投稿