LoginSignup
37
15

More than 3 years have passed since last update.

Vercel(Now.sh)にNuxt.js(SSR)をデプロイすると、Firebase関連でSSR時にNuxt.js Internal Server Errorになるのを修正する

Last updated at Posted at 2020-05-03

めちゃくちゃハマったので、検索でたどり着く人のためにメモ

解決策

Nuxt.js Internal Server Error with firebase · Issue #41 · nuxt/now-builder

nuxt.config.jsに以下を追記

nuxt.config.js
 build: {
    extend ( config, { isDev, isClient, isServer } ) {
      if ( isServer ) {
        config.externals = {
          '@firebase/app': 'commonjs @firebase/app',
          '@firebase/firestore': 'commonjs @firebase/firestore',
          //etc...
        }
      }
    }
}

詳細

Vercel(旧Now.sh)にNuxt.js(SSR)をデプロイしたところ、ログインページをリロードしたところ、Nuxt.js Internal Server Errorが出た。

image.png

nuxt-linkなどで遷移してもエラーは出ないが、ページをリロードすると、エラーになる。

Vercelのログを見るとこうなっていた

render function or template not defined in component: anonymous

image.png

いろいろ調べていくと、Firebaseを使っているページでSSRすると、エラーになるよう。

どうやら、Vercelが内部的にLambdaを使用していて、LambdaとFirebaseは相性が悪いことが原因らしい。

Nuxt.js Internal Server Error with firebase · Issue #41 · nuxt/now-builderに詳細が乗っていた。

上記に従って、以下のようにして解決した

nuxt.config.jsに以下を追記

nuxt.config.js
 build: {
    extend ( config, { isDev, isClient, isServer } ) {
      if ( isServer ) {
        config.externals = {
          '@firebase/app': 'commonjs @firebase/app',
          '@firebase/firestore': 'commonjs @firebase/firestore',
          //etc...
        }
      }
    }
}

以下ツイート

37
15
1

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
37
15