firebase / firebase-tools

The Firebase Command Line Tools
MIT License
4.01k stars 929 forks source link

Updating firebase-functions from 3.19.0 to 4.3.1 leads to `Cannot find module 'firebase-admin/auth'` #5765

Closed dcts closed 1 year ago

dcts commented 1 year ago

Environment info

firebase-tools: 11.29.1

Platform: Linux, Ubuntu 22.04

Updating firebase-functions from ^3.19.0 to ^4.3.1 leads to Cannot find module 'firebase-admin/auth'

After updating a project that has not been touched for at least 1 year, I had to upgrade firebase functions to the latest version. After trying to deploy with the latest firebase tools, the following error appeared:

> functions@ lint /home/dcts/code/shillcoin/shillcoin-backend-reverting/backend
> eslint .

✔  functions: Finished running predeploy script.
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
i  artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled...
✔  functions: required API cloudbuild.googleapis.com is enabled
✔  artifactregistry: required API artifactregistry.googleapis.com is enabled
✔  functions: required API cloudfunctions.googleapis.com is enabled
i  functions: preparing codebase default for deployment
i  functions: Loaded environment variables from .env.

Error: Failed to load function definition from source: Failed to generate manifest from function source: Error: Cannot find module 'firebase-admin/auth'
Require stack:
- /home/dcts/code/shillcoin/shillcoin-backend-reverting/backend/node_modules/firebase-functions/lib/common/providers/identity.js
- /home/dcts/code/shillcoin/shillcoin-backend-reverting/backend/node_modules/firebase-functions/lib/v1/providers/auth.js
- /home/dcts/code/shillcoin/shillcoin-backend-reverting/backend/node_modules/firebase-functions/lib/v1/index.js
- /home/dcts/code/shillcoin/shillcoin-backend-reverting/backend/index.js
- /home/dcts/code/shillcoin/shillcoin-backend-reverting/backend/node_modules/firebase-functions/lib/runtime/loader.js
- /home/dcts/code/shillcoin/shillcoin-backend-reverting/backend/node_modules/firebase-functions/lib/bin/firebase-functions.js
1) If you want to compile the package/file into executable, please pay attention to compilation warnings 
and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable and 
want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() 
or process.execPath.

I removed all require statements and tried to deploy this minimal index.js file, but the same error appeared:

Minimal index.js (same error)

const functions = require('firebase-functions');

exports.helloWorld = functions.https.onRequest((request, response) => {
  response.send("Hello from Firebase!")
});

Debug logs

[2023-05-01T09:41:30.882Z] > 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"]
[2023-05-01T09:41:30.884Z] > authorizing via signed-in user (redingstreet@gmail.com)
[2023-05-01T09:41:30.884Z] [iam] checking project shillcoin for permissions ["cloudfunctions.functions.create","cloudfunctions.functions.delete","cloudfunctions.functions.get","cloudfunctions.functions.list","cloudfunctions.functions.update","cloudfunctions.operations.get","firebase.projects.get"]
[2023-05-01T09:41:30.887Z] >>> [apiv2][query] POST https://cloudresourcemanager.googleapis.com/v1/projects/shillcoin:testIamPermissions [none]
[2023-05-01T09:41:30.887Z] >>> [apiv2][(partial)header] POST https://cloudresourcemanager.googleapis.com/v1/projects/shillcoin:testIamPermissions x-goog-quota-user=projects/shillcoin
[2023-05-01T09:41:30.888Z] >>> [apiv2][body] POST https://cloudresourcemanager.googleapis.com/v1/projects/shillcoin:testIamPermissions {"permissions":["cloudfunctions.functions.create","cloudfunctions.functions.delete","cloudfunctions.functions.get","cloudfunctions.functions.list","cloudfunctions.functions.update","cloudfunctions.operations.get","firebase.projects.get"]}
[2023-05-01T09:41:31.822Z] <<< [apiv2][status] POST https://cloudresourcemanager.googleapis.com/v1/projects/shillcoin:testIamPermissions 200
[2023-05-01T09:41:31.822Z] <<< [apiv2][body] POST https://cloudresourcemanager.googleapis.com/v1/projects/shillcoin:testIamPermissions {"permissions":["cloudfunctions.functions.create","cloudfunctions.functions.delete","cloudfunctions.functions.get","cloudfunctions.functions.list","cloudfunctions.functions.update","cloudfunctions.operations.get","firebase.projects.get"]}
[2023-05-01T09:41:31.823Z] >>> [apiv2][query] POST https://iam.googleapis.com/v1/projects/shillcoin/serviceAccounts/shillcoin@appspot.gserviceaccount.com:testIamPermissions [none]
[2023-05-01T09:41:31.823Z] >>> [apiv2][body] POST https://iam.googleapis.com/v1/projects/shillcoin/serviceAccounts/shillcoin@appspot.gserviceaccount.com:testIamPermissions {"permissions":["iam.serviceAccounts.actAs"]}
[2023-05-01T09:41:32.630Z] <<< [apiv2][status] POST https://iam.googleapis.com/v1/projects/shillcoin/serviceAccounts/shillcoin@appspot.gserviceaccount.com:testIamPermissions 200
[2023-05-01T09:41:32.631Z] <<< [apiv2][body] POST https://iam.googleapis.com/v1/projects/shillcoin/serviceAccounts/shillcoin@appspot.gserviceaccount.com:testIamPermissions {"permissions":["iam.serviceAccounts.actAs"]}

=== Deploying to 'shillcoin'...

i  deploying functions 
Running command: npm --prefix "$RESOURCE_DIR" run lint

> functions@ lint /home/dcts/code/shillcoin/shillcoin-backend-reverting/backend
> eslint .

✔  functions: Finished running predeploy script. 
[2023-05-01T09:41:34.277Z] >>> [apiv2][query] GET https://firebase.googleapis.com/v1beta1/projects/shillcoin [none]
[2023-05-01T09:41:34.680Z] <<< [apiv2][status] GET https://firebase.googleapis.com/v1beta1/projects/shillcoin 200
[2023-05-01T09:41:34.680Z] <<< [apiv2][body] GET https://firebase.googleapis.com/v1beta1/projects/shillcoin {"projectId":"shillcoin","projectNumber":"265713696512","displayName":"shillcoin","name":"projects/shillcoin","resources":{"hostingSite":"shillcoin","storageBucket":"shillcoin.appspot.com","locationId":"us-central"},"state":"ACTIVE","etag":"1_ad937234-1e8b-4d32-8ee3-64991f298dcc"}
i  functions: preparing codebase default for deployment 
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled... 
i  functions: ensuring required API cloudbuild.googleapis.com is enabled... 
i  artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled... 
[2023-05-01T09:41:34.684Z] >>> [apiv2][query] GET https://serviceusage.googleapis.com/v1/projects/shillcoin/services/cloudfunctions.googleapis.com [none]
[2023-05-01T09:41:34.684Z] >>> [apiv2][(partial)header] GET https://serviceusage.googleapis.com/v1/projects/shillcoin/services/cloudfunctions.googleapis.com x-goog-quota-user=projects/shillcoin
[2023-05-01T09:41:34.686Z] >>> [apiv2][query] GET https://serviceusage.googleapis.com/v1/projects/shillcoin/services/runtimeconfig.googleapis.com [none]
[2023-05-01T09:41:34.686Z] >>> [apiv2][(partial)header] GET https://serviceusage.googleapis.com/v1/projects/shillcoin/services/runtimeconfig.googleapis.com x-goog-quota-user=projects/shillcoin
[2023-05-01T09:41:34.688Z] >>> [apiv2][query] GET https://serviceusage.googleapis.com/v1/projects/shillcoin/services/cloudbuild.googleapis.com [none]
[2023-05-01T09:41:34.688Z] >>> [apiv2][(partial)header] GET https://serviceusage.googleapis.com/v1/projects/shillcoin/services/cloudbuild.googleapis.com x-goog-quota-user=projects/shillcoin
[2023-05-01T09:41:34.689Z] >>> [apiv2][query] GET https://serviceusage.googleapis.com/v1/projects/shillcoin/services/artifactregistry.googleapis.com [none]
[2023-05-01T09:41:34.689Z] >>> [apiv2][(partial)header] GET https://serviceusage.googleapis.com/v1/projects/shillcoin/services/artifactregistry.googleapis.com x-goog-quota-user=projects/shillcoin
[2023-05-01T09:41:35.709Z] <<< [apiv2][status] GET https://serviceusage.googleapis.com/v1/projects/shillcoin/services/runtimeconfig.googleapis.com 200
[2023-05-01T09:41:35.710Z] <<< [apiv2][body] GET https://serviceusage.googleapis.com/v1/projects/shillcoin/services/runtimeconfig.googleapis.com [omitted]
[2023-05-01T09:41:35.710Z] <<< [apiv2][status] GET https://serviceusage.googleapis.com/v1/projects/shillcoin/services/artifactregistry.googleapis.com 200
[2023-05-01T09:41:35.710Z] <<< [apiv2][body] GET https://serviceusage.googleapis.com/v1/projects/shillcoin/services/artifactregistry.googleapis.com [omitted]
✔  artifactregistry: required API artifactregistry.googleapis.com is enabled 
[2023-05-01T09:41:35.712Z] <<< [apiv2][status] GET https://serviceusage.googleapis.com/v1/projects/shillcoin/services/cloudfunctions.googleapis.com 200
[2023-05-01T09:41:35.712Z] <<< [apiv2][body] GET https://serviceusage.googleapis.com/v1/projects/shillcoin/services/cloudfunctions.googleapis.com [omitted]
✔  functions: required API cloudfunctions.googleapis.com is enabled 
[2023-05-01T09:41:35.713Z] <<< [apiv2][status] GET https://serviceusage.googleapis.com/v1/projects/shillcoin/services/cloudbuild.googleapis.com 200
[2023-05-01T09:41:35.713Z] <<< [apiv2][body] GET https://serviceusage.googleapis.com/v1/projects/shillcoin/services/cloudbuild.googleapis.com [omitted]
✔  functions: required API cloudbuild.googleapis.com is enabled 
[2023-05-01T09:41:35.714Z] >>> [apiv2][query] GET https://firebase.googleapis.com/v1beta1/projects/shillcoin/adminSdkConfig [none]
[2023-05-01T09:41:36.111Z] <<< [apiv2][status] GET https://firebase.googleapis.com/v1beta1/projects/shillcoin/adminSdkConfig 200
[2023-05-01T09:41:36.111Z] <<< [apiv2][body] GET https://firebase.googleapis.com/v1beta1/projects/shillcoin/adminSdkConfig {"projectId":"shillcoin","storageBucket":"shillcoin.appspot.com","locationId":"us-central"}
[2023-05-01T09:41:36.112Z] >>> [apiv2][query] GET https://runtimeconfig.googleapis.com/v1beta1/projects/shillcoin/configs [none]
[2023-05-01T09:41:36.522Z] <<< [apiv2][status] GET https://runtimeconfig.googleapis.com/v1beta1/projects/shillcoin/configs 200
[2023-05-01T09:41:36.522Z] <<< [apiv2][body] GET https://runtimeconfig.googleapis.com/v1beta1/projects/shillcoin/configs {"configs":[{"name":"projects/shillcoin/configs/youtube"},{"name":"projects/shillcoin/configs/postmark"},{"name":"projects/shillcoin/configs/postmarknft"}]}
[2023-05-01T09:41:36.523Z] >>> [apiv2][query] GET https://runtimeconfig.googleapis.com/v1beta1/projects/shillcoin/configs/youtube/variables [none]
[2023-05-01T09:41:36.525Z] >>> [apiv2][query] GET https://runtimeconfig.googleapis.com/v1beta1/projects/shillcoin/configs/postmark/variables [none]
[2023-05-01T09:41:36.528Z] >>> [apiv2][query] GET https://runtimeconfig.googleapis.com/v1beta1/projects/shillcoin/configs/postmarknft/variables [none]
[2023-05-01T09:41:36.934Z] <<< [apiv2][status] GET https://runtimeconfig.googleapis.com/v1beta1/projects/shillcoin/configs/youtube/variables 200
[2023-05-01T09:41:36.935Z] <<< [apiv2][body] GET https://runtimeconfig.googleapis.com/v1beta1/projects/shillcoin/configs/youtube/variables {"variables":[{"name":"projects/shillcoin/configs/youtube/variables/apikey","updateTime":"2021-07-04T23:10:18.890656950Z"}]}
[2023-05-01T09:41:36.936Z] >>> [apiv2][query] GET https://runtimeconfig.googleapis.com/v1beta1/projects/shillcoin/configs/youtube/variables/apikey [none]
[2023-05-01T09:41:36.938Z] <<< [apiv2][status] GET https://runtimeconfig.googleapis.com/v1beta1/projects/shillcoin/configs/postmark/variables 200
[2023-05-01T09:41:36.939Z] <<< [apiv2][body] GET https://runtimeconfig.googleapis.com/v1beta1/projects/shillcoin/configs/postmark/variables {"variables":[{"name":"projects/shillcoin/configs/postmark/variables/apikey","updateTime":"2021-07-04T23:10:40.529599290Z"}]}
[2023-05-01T09:41:36.939Z] >>> [apiv2][query] GET https://runtimeconfig.googleapis.com/v1beta1/projects/shillcoin/configs/postmark/variables/apikey [none]
[2023-05-01T09:41:36.942Z] <<< [apiv2][status] GET https://runtimeconfig.googleapis.com/v1beta1/projects/shillcoin/configs/postmarknft/variables 200
[2023-05-01T09:41:36.942Z] <<< [apiv2][body] GET https://runtimeconfig.googleapis.com/v1beta1/projects/shillcoin/configs/postmarknft/variables {"variables":[{"name":"projects/shillcoin/configs/postmarknft/variables/apikey","updateTime":"2021-11-04T04:46:34.054517640Z"}]}
[2023-05-01T09:41:36.942Z] >>> [apiv2][query] GET https://runtimeconfig.googleapis.com/v1beta1/projects/shillcoin/configs/postmarknft/variables/apikey [none]
[2023-05-01T09:41:37.342Z] <<< [apiv2][status] GET https://runtimeconfig.googleapis.com/v1beta1/projects/shillcoin/configs/postmarknft/variables/apikey 200
[2023-05-01T09:41:37.343Z] <<< [apiv2][body] GET https://runtimeconfig.googleapis.com/v1beta1/projects/shillcoin/configs/postmarknft/variables/apikey {"name":"projects/shillcoin/configs/postmarknft/variables/apikey","updateTime":"2021-11-04T04:46:34.054517640Z","text":"6ed487db-7421-4490-8ceb-b47456313fbc"}
[2023-05-01T09:41:37.346Z] <<< [apiv2][status] GET https://runtimeconfig.googleapis.com/v1beta1/projects/shillcoin/configs/postmark/variables/apikey 200
[2023-05-01T09:41:37.346Z] <<< [apiv2][body] GET https://runtimeconfig.googleapis.com/v1beta1/projects/shillcoin/configs/postmark/variables/apikey {"name":"projects/shillcoin/configs/postmark/variables/apikey","updateTime":"2021-07-04T23:10:40.529599290Z","text":"f65dd453-94d1-400f-86bf-119f64437cad"}
[2023-05-01T09:41:37.347Z] <<< [apiv2][status] GET https://runtimeconfig.googleapis.com/v1beta1/projects/shillcoin/configs/youtube/variables/apikey 200
[2023-05-01T09:41:37.347Z] <<< [apiv2][body] GET https://runtimeconfig.googleapis.com/v1beta1/projects/shillcoin/configs/youtube/variables/apikey {"name":"projects/shillcoin/configs/youtube/variables/apikey","updateTime":"2021-07-04T23:10:18.890656950Z","text":"AIzaSyCauLVkx2TAPBbZdDvlnRt-i8LHBzDDhWo"}
[2023-05-01T09:41:37.349Z] Validating nodejs source
[2023-05-01T09:41:38.080Z] > [functions] package.json contents: {
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "eslint .",
    "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": "16"
  },
  "main": "index.js",
  "dependencies": {
    "firebase-admin": "^9.12.0",
    "firebase-functions": "^4.3.1"
  },
  "devDependencies": {
    "dotenv": "^8.6.0",
    "eslint": "^5.12.0",
    "eslint-plugin-promise": "^4.3.1",
    "firebase-functions-test": "^0.2.0"
  },
  "private": true
}
[2023-05-01T09:41:38.081Z] Building nodejs source
[2023-05-01T09:41:38.083Z] Could not find functions.yaml. Must use http discovery
[2023-05-01T09:41:38.091Z] Found firebase-functions binary at '/home/dcts/code/shillcoin/shillcoin-backend-reverting/backend/node_modules/.bin/firebase-functions'
[2023-05-01T09:41:38.286Z] Serving at port 8203

[2023-05-01T09:41:38.306Z] Got response from /__/functions.yaml Failed to generate manifest from function source: Error: Cannot find module 'firebase-admin/auth'
Require stack:
- /home/dcts/code/shillcoin/shillcoin-backend-reverting/backend/node_modules/firebase-functions/lib/common/providers/identity.js
- /home/dcts/code/shillcoin/shillcoin-backend-reverting/backend/node_modules/firebase-functions/lib/v1/providers/auth.js
- /home/dcts/code/shillcoin/shillcoin-backend-reverting/backend/node_modules/firebase-functions/lib/v1/index.js
- /home/dcts/code/shillcoin/shillcoin-backend-reverting/backend/index.js
- /home/dcts/code/shillcoin/shillcoin-backend-reverting/backend/node_modules/firebase-functions/lib/runtime/loader.js
- /home/dcts/code/shillcoin/shillcoin-backend-reverting/backend/node_modules/firebase-functions/lib/bin/firebase-functions.js
[2023-05-01T09:41:38.312Z] Failed to parse functions.yamlincomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line at line 1, column 56:
     ... fest from function source: Error: Cannot find module 'firebase-a ... 
                                         ^ {"name":"YAMLException","reason":"incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line","mark":{"name":null,"buffer":"Failed to generate manifest from function source: Error: Cannot find module 'firebase-admin/auth'\nRequire stack:\n- /home/dcts/code/shillcoin/shillcoin-backend-reverting/backend/node_modules/firebase-functions/lib/common/providers/identity.js\n- /home/dcts/code/shillcoin/shillcoin-backend-reverting/backend/node_modules/firebase-functions/lib/v1/providers/auth.js\n- /home/dcts/code/shillcoin/shillcoin-backend-reverting/backend/node_modules/firebase-functions/lib/v1/index.js\n- /home/dcts/code/shillcoin/shillcoin-backend-reverting/backend/index.js\n- /home/dcts/code/shillcoin/shillcoin-backend-reverting/backend/node_modules/firebase-functions/lib/runtime/loader.js\n- /home/dcts/code/shillcoin/shillcoin-backend-reverting/backend/node_modules/firebase-functions/lib/bin/firebase-functions.js\n\u0000","position":55,"line":0,"column":55},"message":"incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line at line 1, column 56:\n     ... fest from function source: Error: Cannot find module 'firebase-a ... \n                                         ^"}
[2023-05-01T09:41:38.320Z] shutdown requested via /__/quitquitquit

Error: Failed to load function definition from source: Failed to generate manifest from function source: Error: Cannot find module 'firebase-admin/auth'
Require stack:
- /home/dcts/code/shillcoin/shillcoin-backend-reverting/backend/node_modules/firebase-functions/lib/common/providers/identity.js
- /home/dcts/code/shillcoin/shillcoin-backend-reverting/backend/node_modules/firebase-functions/lib/v1/providers/auth.js
- /home/dcts/code/shillcoin/shillcoin-backend-reverting/backend/node_modules/firebase-functions/lib/v1/index.js
- /home/dcts/code/shillcoin/shillcoin-backend-reverting/backend/index.js
- /home/dcts/code/shillcoin/shillcoin-backend-reverting/backend/node_modules/firebase-functions/lib/runtime/loader.js
- /home/dcts/code/shillcoin/shillcoin-backend-reverting/backend/node_modules/firebase-functions/lib/bin/firebase-functions.js
google-oss-bot commented 1 year ago

This issue does not seem to follow the issue template. Make sure you provide all the required information.

dcts commented 1 year ago

This was caused due to dependency conflicts. Updating firebase-admin to greater than 10.0.0 or 11.0.0 using below command fixed the issue:

npm i --save firebase-admin@10.3.0