発生した問題
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を指定するとエラーが消えるよう。