Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
5
Help us understand the problem. What are the problem?

More than 1 year has passed since last update.

posted at

updated at

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

発生した問題

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を指定するとエラーが消えるよう。

参考サイト

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
5
Help us understand the problem. What are the problem?