firebase-tools icon indicating copy to clipboard operation
firebase-tools copied to clipboard

TypeError: Cannot read properties of undefined (reading 'user')

Open EpicEric3ric opened this issue 5 months ago • 3 comments

[REQUIRED] Environment info firebase-tools: 14.4.0

Platform: macOS

[REQUIRED] Test case functions/package.json content:

JSON

{ "name": "functions", "description": "Cloud Functions for Firebase", "scripts": { "serve": "firebase emulators:start --only functions", "shell": "firebase functions:shell", "lint": "eslint .", "start": "npm run shell", "deploy": "firebase deploy --only functions", "logs": "firebase functions:log" }, "engines": { "node": "22" }, "main": "index.js", "type": "module", "dependencies": { "eslint": "^9.28.0", "express": "^5.1.0", "firebase-admin": "^13.4.0", "firebase-functions": "^6.3.2", "stripe": "^18.2.1" }, "devDependencies": { "eslint-config-google": "^0.14.0", "firebase-functions-test": "^3.1.0" }, "private": true } functions/index.js content (minimal test case):

JavaScript

import * as functions from 'firebase-functions'; import { initializeApp } from 'firebase-admin/app'; import * as admin from 'firebase-admin'; // Keep this for admin.firestore() etc.

initializeApp();

export const testAuthTriggerMinimal = functions.auth.user().onCreate((user) => { console.log('New user created in new project:', user.uid); return null; // Or return admin.firestore().collection('users').doc(user.uid).set({...}); if you want to test that fully }); Node.js Version: v22.14.0 Node.js Executable Path: /usr/local/bin/node

[REQUIRED] Steps to reproduce Create a brand new Firebase project in the Firebase Console (e.g., my-auth-test-project-250617). Initialize a new Firebase project locally in an empty directory: mkdir ~/temp-firebase-auth-test && cd ~/temp-firebase-auth-test Run firebase init functions and link to the new Firebase project created in step 1. Select JavaScript, decline ESLint, and allow npm install to run. Navigate into the functions directory: cd functions Update the functions/package.json content as provided in the "Test case" section above (ensure engines.node is "22", "type": "module" is added, and firebase-admin and firebase-functions are updated to ^13.4.0 and ^6.3.2 respectively, along with other dependencies if needed). Run npm install in the functions directory to install updated dependencies. Replace the content of functions/index.js with the minimal test case provided in the "Test case" section above. Navigate back to the project root: cd .. Attempt to deploy the function: firebase deploy --only functions:testAuthTriggerMinimal --debug [REQUIRED] Expected behavior The testAuthTriggerMinimal Cloud Function should deploy successfully to the Firebase project.

[REQUIRED] Actual behavior The deployment fails during the "Loading and analyzing source code" phase with a TypeError: Cannot read properties of undefined (reading 'user') error.

Full Debug Log:

[debug] [2025-06-17T20:25:34.292Z] ---------------------------------------------------------------------- [debug] [2025-06-17T20:25:34.293Z] Command: /usr/local/bin/node /usr/local/bin/firebase deploy --only functions:testAuthTriggerMinimal --debug [debug] [2025-06-17T20:25:34.294Z] CLI Version: 14.4.0 [debug] [2025-06-17T20:25:34.294Z] Platform: darwin [debug] [2025-06-17T20:25:34.294Z] Node Version: v22.14.0 [debug] [2025-06-17T20:25:34.294Z] Time: Tue Jun 17 2025 13:25:34 GMT-0700 (Pacific Daylight Time) [debug] [2025-06-17T20:25:34.294Z] ---------------------------------------------------------------------- [debug] [debug] [2025-06-17T20:25:34.396Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"] [debug] [2025-06-17T20:25:34.397Z] > authorizing via signed-in user (...redacted...) [debug] [2025-06-17T20:25:34.397Z] [iam] checking project my-auth-test-project-250617 for permissions ["cloudfunctions.functions.create","cloudfunctions.functions.delete","cloudfunctions.functions.get","cloudfunctions.functions.list","cloudfunctions.functions.update","cloudfunctions.operations.get","firebase.projects.get"] [debug] [2025-06-17T20:25:34.397Z] Checked if tokens are valid: true, expires at: 1750192859920 [debug] [2025-06-17T20:25:34.398Z] Checked if tokens are valid: true, expires at: 1750192859920 [debug] [2025-06-17T20:25:34.398Z] >>> [apiv2][query] POST https://cloudresourcemanager.googleapis.com/v1/projects/my-auth-test-project-250617:testIamPermissions [none] [debug] [2025-06-17T20:25:34.398Z] >>> [apiv2][(partial)header] POST https://cloudresourcemanager.googleapis.com/v1/projects/my-auth-test-project-250617:testIamPermissions x-goog-quota-user=projects/my-auth-test-project-250617 [debug] [2025-06-17T20:25:34.398Z] >>> [apiv2][body] POST https://cloudresourcemanager.googleapis.com/v1/projects/my-auth-test-project-250617:testIamPermissions {"permissions":["cloudfunctions.functions.create","cloudfunctions.functions.delete","cloudfunctions.functions.get","cloudfunctions.functions.list","cloudfunctions.functions.update","cloudfunctions.operations.get","firebase.projects.get"]} [debug] [2025-06-17T20:25:34.540Z] <<< [apiv2][status] POST https://cloudresourcemanager.googleapis.com/v1/projects/my-auth-test-project-250617:testIamPermissions 200 [debug] [2025-06-17T20:25:34.540Z] <<< [apiv2][body] POST https://cloudresourcemanager.googleapis.com/v1/projects/my-auth-test-project-250617:testIamPermissions {"permissions":["cloudfunctions.functions.create","cloudfunctions.functions.delete","cloudfunctions.functions.get","cloudfunctions.functions.list","cloudfunctions.functions.update","cloudfunctions.operations.get","firebase.projects.get"]} [debug] [2025-06-17T20:25:34.540Z] Checked if tokens are valid: true, expires at: 1750192859920 [debug] [2025-06-17T20:25:34.540Z] Checked if tokens are valid: true, expires at: 1750192859920 [debug] [2025-06-17T20:25:34.540Z] >>> [apiv2][query] POST https://iam.googleapis.com/v1/projects/my-auth-test-project-250617/serviceAccounts/[email protected]:testIamPermissions [none] [debug] [2025-06-17T20:25:34.541Z] >>> [apiv2][body] POST https://iam.googleapis.com/v1/projects/my-auth-test-project-250617/serviceAccounts/[email protected]:testIamPermissions {"permissions":["iam.serviceAccounts.actAs"]} [debug] [2025-06-17T20:25:34.875Z] <<< [apiv2][status] POST https://iam.googleapis.com/v1/projects/my-auth-test-project-250617/serviceAccounts/[email protected]:testIamPermissions 200 [debug] [2025-06-17T20:25:34.875Z] <<< [apiv2][body] POST https://iam.googleapis.com/v1/projects/my-auth-test-project-250617/serviceAccounts/[email protected]:testIamPermissions {"permissions":["iam.serviceAccounts.actAs"]} [info] [info] === Deploying to 'my-auth-test-project-250617'... [info] [info] i deploying functions [debug] [2025-06-17T20:25:34.879Z] Checked if tokens are valid: true, expires at: 1750192859920 [debug] [2025-06-17T20:25:34.879Z] Checked if tokens valid: true, expires at: 1750192859920 [debug] [2025-06-17T20:25:34.879Z] >>> [apiv2][query] GET https://serviceusage.googleapis.com/v1/projects/my-auth-test-project-250617/services/cloudresourcemanager.googleapis.com [none] [debug] [2025-06-17T20:25:34.879Z] >>> [apiv2][(partial)header] GET https://serviceusage.googleapis.com/v1/projects/my-auth-test-project-250617/services/cloudresourcemanager.googleapis.com x-goog-quota-user=projects/my-auth-test-project-250617 [debug] [2025-06-17T20:25:35.307Z] <<< [apiv2][status] GET https://serviceusage.googleapis.com/v1/projects/my-auth-test-project-250617/services/cloudresourcemanager.googleapis.com 200 [debug] [2025-06-17T20:25:35.307Z] <<< [apiv2][body] GET https://serviceusage.googleapis.com/v1/projects/my-auth-test-project-250617/services/cloudresourcemanager.googleapis.com [omitted] [debug] [2025-06-17T20:25:35.307Z] Checked if tokens are valid: true, expires at: 1750192859920 [debug] [2025-06-17T20:25:35.307Z] Checked if tokens are valid: true, expires at: 1750192859920 [debug] [2025-06-17T20:25:35.307Z] >>> [apiv2][query] GET https://cloudresourcemanager.googleapis.com/v1/projects/my-auth-test-project-250617/projects [none] [debug] [2025-06-17T20:25:35.426Z] <<< [apiv2][status] GET https://cloudresourcemanager.googleapis.com/v1/projects/my-auth-test-project-250617/projects 200 [debug] [2025-06-17T20:25:35.427Z] <<< [apiv2][body] GET https://cloudresourcemanager.googleapis.com/v1/projects/my-auth-test-project-250617/projects {"projectNumber":"789948579393","projectId":"my-auth-test-project-250617","lifecycleState":"ACTIVE","name":"my-auth-test-project-250617","labels":{"firebase":"enabled","firebase-core":"disabled"},"createTime":"2025-06-17T20:14:15.310178Z","parent":{"type":"organization","id":"746706309597"}} [info] i functions: preparing codebase default for deployment [info] i functions: ensuring required API cloudfunctions.googleapis.com is enabled... [debug] [2025-06-17T20:25:35.430Z] Checked if tokens are valid: true, expires at: 1750192859920 [debug] [2025-06-17T20:25:35.430Z] Checked if tokens are valid: true, expires at: 1750192859920 [debug] [2025-06-17T20:25:35.430Z] Checked if tokens are valid: true, expires at: 1750192859920 [debug] [2025-06-17T20:25:35.430Z] Checked if tokens are valid: true, expires at: 1750192859920 [info] i functions: ensuring required API cloudbuild.googleapis.com is enabled... [debug] [2025-06-17T20:25:35.430Z] Checked if tokens are valid: true, expires at: 1750192859920 [debug] [2025-06-17T20:25:35.430Z] Checked if tokens are valid: true, expires at: 1750192859920 [info] i artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled... [debug] [2025-06-17T20:25:35.431Z] Checked if tokens are valid: true, expires at: 1750192859920 [debug] [2025-06-17T20:25:35.431Z] Checked if tokens are valid: true, expires at: 1750192859920 [debug] [2025-06-17T20:25:35.431Z] >>> [apiv2][query] GET https://serviceusage.googleapis.com/v1/projects/my-auth-test-project-250617/services/cloudfunctions.googleapis.com [none] [debug] [2025-06-17T20:25:35.431Z] >>> [apiv2][(partial)header] GET https://serviceusage.googleapis.com/v1/projects/my-auth-test-project-250617/services/cloudfunctions.googleapis.com x-goog-quota-user=projects/my-auth-test-project-250617 [debug] [2025-06-17T20:25:35.431Z] >>> [apiv2][query] GET https://serviceusage.googleapis.com/v1/projects/my-auth-test-project-250617/services/runtimeconfig.googleapis.com [none] [debug] [2025-06-17T20:25:35.432Z] >>> [apiv2][(partial)header] GET https://serviceusage.googleapis.com/v1/projects/my-auth-test-project-250617/services/runtimeconfig.googleapis.com x-goog-quota-user=projects/my-auth-test-project-250617 [debug] [2025-06-17T20:25:35.433Z] >>> [apiv2][query] GET https://serviceusage.googleapis.com/v1/projects/my-auth-test-project-250617/services/cloudbuild.googleapis.com [none] [debug] [2025-06-17T20:25:35.433Z] >>> [apiv2][(partial)header] GET https://serviceusage.googleapis.com/v1/projects/my-auth-test-project-250617/services/cloudbuild.googleapis.com x-goog-quota-user=projects/my-auth-test-project-250617 [debug] [2025-06-17T20:25:35.435Z] >>> [apiv2][query] GET https://serviceusage.googleapis.com/v1/projects/my-auth-test-project-250617/services/artifactregistry.googleapis.com [none] [debug] [2025-06-17T20:25:35.435Z] >>> [apiv2][(partial)header] GET https://serviceusage.googleapis.com/v1/projects/my-auth-test-project-250617/services/artifactregistry.googleapis.com x-goog-quota-user=projects/my-auth-test-project-250617 [debug] [2025-06-17T20:25:35.814Z] <<< [apiv2][status] GET https://serviceusage.googleapis.com/v1/projects/my-auth-test-project-250617/services/cloudbuild.googleapis.com 200 [debug] [2025-06-17T20:25:35.814Z] <<< [apiv2][body] GET https://serviceusage.googleapis.com/v1/projects/my-auth-test-project-250617/services/cloudbuild.googleapis.com [omitted] [info] functions: required API cloudbuild.googleapis.com is enabled [debug] [2025-06-17T20:25:35.816Z] <<< [apiv2][status] GET https://serviceusage.googleapis.com/v1/projects/my-auth-test-project-250617/services/cloudfunctions.googleapis.com 200 [debug] [2025-06-17T20:25:35.816Z] <<< [apiv2][body] GET https://serviceusage.googleapis.com/v1/projects/my-auth-test-project-250617/services/cloudfunctions.googleapis.com [omitted] [info] functions: required API cloudfunctions.googleapis.com is enabled [debug] [2025-06-17T20:25:35.844Z] <<< [apiv2][status] GET https://serviceusage.googleapis.com/v1/projects/my-auth-test-project-250617/services/runtimeconfig.googleapis.com 200 [debug] [2025-06-17T20:25:35.845Z] <<< [apiv2][body] GET https://serviceusage.googleapis.com/v1/projects/my-auth-test-project-250617/services/runtimeconfig.googleapis.com [omitted] [debug] [2025-06-17T20:25:35.854Z] <<< [apiv2][status] GET https://serviceusage.googleapis.com/v1/projects/my-auth-test-project-250617/services/artifactregistry.googleapis.com 200 [debug] [2025-06-17T20:25:35.854Z] <<< [apiv2][body] GET https://serviceusage.googleapis.com/v1/projects/my-auth-test-project-250617/services/artifactregistry.googleapis.com [omitted] [info] artifactregistry: required API artifactregistry.googleapis.com is enabled [debug] [2025-06-17T20:25:35.855Z] Checked if tokens are valid: true, expires at: 1750192859920 [debug] [2025-06-17T20:25:35.855Z] Checked if tokens are valid: true, expires at: 1750192859920 [debug] [2025-06-17T20:25:35.855Z] >>> [apiv2][query] GET https://firebase.googleapis.com/v1beta1/projects/my-auth-test-project-250617/adminSdkConfig [none] [debug] [2025-06-17T20:25:36.074Z] <<< [apiv2][status] GET https://firebase.googleapis.com/v1beta1/projects/my-auth-test-project-250617/adminSdkConfig 200 [debug] [2025-06-17T20:25:36.075Z] <<< [apiv2][body] GET https://firebase.googleapis.com/v1beta1/projects/my-auth-test-project-250617/adminSdkConfig {"projectId":"my-auth-test-project-250617","storageBucket":"my-auth-test-project-250617.firebasestorage.app"} [debug] [2025-06-17T20:25:36.076Z] Checked if tokens are valid: true, expires at: 1750192859920 [debug] [2025-06-17T20:25:36.076Z] Checked if tokens are valid: true, expires at: 1750192859920 [debug] [2025-06-17T20:25:36.077Z] >>> [apiv2][query] GET https://runtimeconfig.googleapis.com/v1beta1/projects/my-auth-test-project-250617/configs [none] [debug] [2025-06-17T20:25:36.222Z] <<< [apiv2][status] GET https://runtimeconfig.googleapis.com/v1beta1/projects/my-auth-test-project-250617/configs 200 [debug] [2025-06-17T20:25:36.222Z] <<< [apiv2][body] GET https://runtimeconfig.googleapis.com/v1beta1/projects/my-auth-test-project-250617/configs {} [debug] [2025-06-17T20:25:36.224Z] Validating nodejs source [debug] [2025-06-17T20:25:36.678Z] > [functions] package.json contents: { "name": "functions", "description": "Cloud Functions for Firebase", "scripts": { "serve": "firebase emulators:start --only functions", "shell": "firebase functions:shell", "start": "npm run shell", "deploy": "firebase deploy --only functions", "logs": "firebase functions:log" }, "engines": { "node": "22" }, "main": "index.js", "type": "module", "dependencies": { "firebase-admin": "^13.4.0", "firebase-functions": "^6.3.2" }, "devDependencies": { "firebase-functions-test": "^3.1.0" }, "private": true } [debug] [2025-06-17T20:25:36.678Z] Building nodejs source [info] i functions: Loading and analyzing source code for codebase default to determine what to deploy [debug] [2025-06-17T20:25:36.679Z] Could not find functions.yaml. Must use http discovery [debug] [2025-06-17T20:25:36.683Z] Found firebase-functions binary at '/Users/egner/FirebaseAuthIssue/temp-firebase-auth-test/functions/node_modules/.bin/firebase-functions' [info] Serving at port 8931

[error] TypeError: Cannot read properties of undefined (reading 'user') at file:///Users/egner/FirebaseAuthIssue/temp-firebase-auth-test/functions/index.js:17:54 at ModuleJobSync.runSync (node:internal/modules/esm/module_job:395:35) at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:360:47) at loadESMFromCJS (node:internal/modules/cjs/loader:1385:24) at Module._compile (node:internal/modules/cjs/loader:1536:5) at Object..js (node:internal/modules/cjs/loader:1706:10) at Module.load (node:internal/modules/cjs/loader:1289:32) at Function._load (node:internal/modules/cjs/loader:1108:12) at TracingChannel.traceSync (node:diagnostics_channel:322:14) at wrapModuleLoad (node:internal/modules/cjs/loader:220:24)

[debug] [2025-06-17T20:25:37.063Z] Got response code 400; body Failed to generate manifest from function source: TypeError: Cannot read properties of undefined (reading 'user') [error] [error] Error: Functions codebase could not be analyzed successfully. It may have a syntax or runtime error

EpicEric3ric avatar Jun 17 '25 20:06 EpicEric3ric

Hey @EpicEric3ric, thanks for the detailed report! Looking at the code you provided, it seems like you're trying to use v1 functions instead of v2 functions. For context starting firebase-functions v6.0.0 the default entry point of the package was changed to v2 instead of v1.

Try updating you code to explicitly import from firebase-functions/v1

import * as functions from 'firebase-functions/v1'; // explicitly imports v1 functions
import { initializeApp } from 'firebase-admin/app';
import * as admin from 'firebase-admin'; // Keep this for admin.firestore() etc.

initializeApp();

export const testAuthTriggerMinimal = functions.auth.user().onCreate((user) => {
    console.log('New user created in new project:', user.uid);
    return null; // Or return admin.firestore().collection('users').doc(user.uid).set({...}); if you want to test that fully
});

Do you still see any errors after updating the code?

edit:

I noticed you were using node 22 as your engine in package.json. You might encounter an error when deploying since nodejs22 is not a valid runtime for 1st gen functions, see this issue https://github.com/firebase/firebase-tools/issues/8704. If you do encounter an INVALID_RUNTIME error when deploying, try changing your engine to use node 20.

...
"engines": {
"node": "20"
},
...

aalej avatar Jun 18 '25 12:06 aalej

Will do and thanks for the follow up! I'll work on it when I can.

Sincerely,

Eric

On Wed, Jun 18, 2025, 05:12 aalej @.***> wrote:

aalej left a comment (firebase/firebase-tools#8765) https://github.com/firebase/firebase-tools/issues/8765#issuecomment-2983950922

Hey @EpicEric3ric https://github.com/EpicEric3ric, thanks for the detailed report! Looking at the code you provided, it seems like you're trying to use v1 functions instead of v2 functions. For context starting firebase-functions v6.0.0 https://github.com/firebase/firebase-functions/releases/tag/v6.0.0 the default entry point of the package was changed to v2 instead of v1.

Try updating you code to explicitly import from firebase-functions/v1

import * as functions from 'firebase-functions/v1'; // explicitly imports v1 functionsimport { initializeApp } from 'firebase-admin/app';import * as admin from 'firebase-admin'; // Keep this for admin.firestore() etc. initializeApp(); export const testAuthTriggerMinimal = functions.auth.user().onCreate((user) => { console.log('New user created in new project:', user.uid); return null; // Or return admin.firestore().collection('users').doc(user.uid).set({...}); if you want to test that fully});

Do you still see any errors after updating the code?

— Reply to this email directly, view it on GitHub https://github.com/firebase/firebase-tools/issues/8765#issuecomment-2983950922, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALOIFCVAYKOHNYA2CE3QT7L3EFJSHAVCNFSM6AAAAAB7RICTLKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSOBTHE2TAOJSGI . You are receiving this because you were mentioned.Message ID: @.***>

EpicEric3ric avatar Jun 25 '25 02:06 EpicEric3ric

Hey @EpicEric3ric, just checking if you were able to resolve the issue?

aalej avatar Jun 26 '25 16:06 aalej

We can close this out will work on updating our system. Sorry about that!

EpicEric3ric avatar Jun 30 '25 21:06 EpicEric3ric