Google Cloud Functionsでnode.jsを使う場合、devDependenciesを使うとデプロイが失敗する

Google Cloud Functionsのプロジェクトではnpm install --save-devyarn add --devは使わずに、npm installyarn addを使うこと。

もししてしまっても、package.jsondevDependenciesを手動でdependenciesに移せば大丈夫。

問題

これになる 👇

$ yarn deploy
yarn run v1.22.5
$ firebase deploy --only functions

=== Deploying to 'foo'...

i  deploying functions
Running command: yarn build
$ tsc

...

✔  functions: . folder uploaded successfully
i  functions: updating Node.js 12 function bar(us-central1)...
⚠  functions[bar(us-central1)]: Deployment error.
Function failed on loading user code. This is likely due to a bug in the user code.
Error message: Error: please examine your function logs to see the error cause: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs.
Additional troubleshooting documentation can be found at https://cloud.google.com/functions/docs/troubleshooting#logging.
Please visit https://cloud.google.com/functions/docs/troubleshooting for in-depth troubleshooting documentation.

...

package.jsonの一部

  "devDependencies": {
    "request-promise-native": "^1.0.9"
  },

解決

長らく悩んで GCPのログエクスプローラーを見てみると、ちゃんと書いてあった……。

{
  "textPayload": "Did you list all required modules in the package.json dependencies?",
  "insertId": "000000-ad829364-20bb-4471-96d7-51b483614caf",
  "resource": {
    "type": "cloud_function",
    "labels": {
      "project_id": "foo",
      "function_name": "bar",
      "region": "us-central1"
    }
  },
  "timestamp": "2021-01-09T13:54:40.865Z",
  "labels": {
    "execution_id": ""
  },
  "logName": "projects/foo/logs/cloudfunctions.googleapis.com%2Fcloud-functions",
  "receiveTimestamp": "2021-01-09T13:54:42.400107672Z"
}

ぴえんでございます!!!!!

筆者プロフィール

my-latest-logo

aiya000(あいや)

せつラボ 〜圏論の基本〜」 「せつラボ2~雲と天使と関手圏~」 「矢澤にこ先輩といっしょに代数!」を書いています!

強い静的型付けとテストを用いて、バグを防ぐのが好き。Haskell・TypeScript。