LoginSignup
5
5

More than 3 years have passed since last update.

[Cloud Functions] Node.jsのバージョンを10にしたら「TypeError: Cannot read property 'charCodeAt' of undefined」ってエラーが出た

Last updated at Posted at 2020-06-25

発生した問題

FirestoreのバックアップをCloudFunctionsで行っていたのだが、
Node.js 8 ランタイムが非推奨になり10にアップデートしないといけなかったので変更したら
変更後に以下のエラーが発生するようになった。

TypeError: Cannot read property 'charCodeAt' of undefined
    at peg$parsetemplate (/workspace/node_modules/google-gax/build/src/pathTemplateParser.js:320:17)
    at Object.peg$parse [as parse] (/workspace/node_modules/google-gax/build/src/pathTemplateParser.js:649:18)
    at new PathTemplate (/workspace/node_modules/google-gax/build/src/pathTemplate.js:32:54)
    at segments.forEach.segment (/workspace/node_modules/google-gax/build/src/pathTemplate.js:103:29)
    at Array.forEach (<anonymous>)
    at PathTemplate.render (/workspace/node_modules/google-gax/build/src/pathTemplate.js:97:23)
    at FirestoreAdminClient.databasePath (/workspace/node_modules/@google-cloud/firestore/build/src/v1/firestore_admin_client.js:792:57)
    at exports.scheduledFirestoreExport.functions.region.pubsub.schedule.timeZone.onRun (/workspace/index.js:11:12)
    at cloudFunction (/workspace/node_modules/firebase-functions/lib/cloud-functions.js:127:23)
    at Promise.resolve.then (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:330:28) 

解決策

FirestoreAdminClientのdatabasePathのprojectの指定を以下に変更した。

Before

const databaseName = client.databasePath(process.env.GCP_PROJECT, '(default)');

After

const projectId = process.env.GCP_PROJECT || process.env.GCLOUD_PROJECT;
const databaseName = client.databasePath(projectId, '(default)');

どうやらGCLOUD_PROJECTを指定するとエラーが消えるよう。

参考サイト

5
5
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
5
5