Search code examples
node.jsfirebasegoogle-cloud-functionsangular-ssr

How to Solve this issue "Error: An unexpected error has occurred."


I can not understand why this problem occurred. I tried all possible ways to solve this problem but I couldn't find proper solutions to solve this problem. I use angular 15 here with SSR. but that time it's works fine, when I added @angular/fire package to my project after that I found this problem. Now My project does not deploy in the Firebase hosting. My Project is Stuck now.

Console Messages

=== Deploying to 'softwares-techy'...

i  deploying database, storage, firestore, functions, hosting, remoteconfig
Running command: npm --prefix "$RESOURCE_DIR" run build

> app-apis@0.0.1 build
> npm-run-all nest:build


> app-apis@0.0.1 prenest:build
> rimraf dist


> app-apis@0.0.1 nest:build
> nest build

✔  functions: Finished running predeploy script.
i  database: checking rules syntax...
✔  database: rules syntax for database softwares-techy-default-rtdb is valid
i  firebase.storage: checking storage.rules for compilation errors...
✔  firebase.storage: rules file storage.rules compiled successfully
i  firestore: reading indexes from firestore.indexes.json...
i  cloud.firestore: checking firestore.rules for compilation errors...
✔  cloud.firestore: rules file firestore.rules compiled successfully
i  functions: preparing codebase app-apis for deployment
i  functions: preparing codebase firebase-frameworks-softwares-techy 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...
✔  artifactregistry: required API artifactregistry.googleapis.com is enabled
✔  functions: required API cloudbuild.googleapis.com is enabled
✔  functions: required API cloudfunctions.googleapis.com is enabled
⚠  functions: package.json indicates an outdated version of firebase-functions. Please upgrade using npm install --save firebase-functions@latest in your functions directory.
⚠  functions: Please note that there will be breaking changes when you upgrade.
i  functions: Loaded environment variables from .env.
i  functions: preparing app-apis directory for uploading...
i  functions: packaged /Users/shibaji/Desktop/project/My Websites/Softwares Techy/app-apis (172.43 KB) for uploading
i  functions: preparing .firebase/softwares-techy/functions directory for uploading...
i  functions: packaged /Users/shibaji/Desktop/project/My Websites/Softwares Techy/.firebase/softwares-techy/functions (3.32 MB) for uploading

Error: An unexpected error has occurred.

and firebase-debug.log files message is

[debug] [2023-04-07T06:16:40.337Z] Building nodejs source
[debug] [2023-04-07T06:16:40.338Z] Could not find functions.yaml. Must use http discovery
[debug] [2023-04-07T06:16:40.342Z] Found firebase-functions binary at '/Users/shibaji/Desktop/project/My Websites/Softwares Techy/app-apis/node_modules/.bin/firebase-functions'
[debug] [2023-04-07T06:16:40.467Z] Serving at port 8044

[debug] [2023-04-07T06:16:40.836Z] [Nest] 27359  - 04/07/2023, 11:46:40 AM     LOG [NestFactory] Starting Nest application...

[debug] [2023-04-07T06:16:40.839Z] Got response from /__/functions.yaml {"endpoints":{"api":{"platform":"gcfv1","availableMemoryMb":null,"timeoutSeconds":null,"minInstances":null,"maxInstances":null,"ingressSettings":null,"serviceAccountEmail":null,"vpc":null,"httpsTrigger":{},"entryPoint":"api"}},"specVersion":"v1alpha1","requiredAPIs":[]}
[debug] [2023-04-07T06:16:40.842Z] [Nest] 27359  - 04/07/2023, 11:46:40 AM     LOG [InstanceLoader] AppModule dependencies initialized +7ms

[debug] [2023-04-07T06:16:40.851Z] [Nest] 27359  - 04/07/2023, 11:46:40 AM     LOG [RoutesResolver] AppController {/}: +8ms

[debug] [2023-04-07T06:16:40.851Z] [Nest] 27359  - 04/07/2023, 11:46:40 AM     LOG [RouterExplorer] Mapped {/, GET} route +1ms

[debug] [2023-04-07T06:16:40.852Z] [Nest] 27359  - 04/07/2023, 11:46:40 AM     LOG [NestApplication] Nest application successfully started +1ms

[debug] [2023-04-07T06:16:40.853Z] Nest Ready

[debug] [2023-04-07T06:16:40.854Z] shutdown requested via /__/quitquitquit

[debug] [2023-04-07T06:16:40.860Z] Validating nodejs source
[warn] ⚠  functions: package.json indicates an outdated version of firebase-functions. Please upgrade using npm install --save firebase-functions@latest in your functions directory. 
[warn] ⚠  functions: Please note that there will be breaking changes when you upgrade. 
[debug] [2023-04-07T06:16:41.368Z] > [functions] package.json contents: {
  "name": "web-app",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test",
    "dev:ssr": "ng run web-app:serve-ssr",
    "serve:ssr": "node dist/web-app/server/main.js",
    "build:ssr": "ng build && ng run web-app:server",
    "prerender": "ng run web-app:prerender",
    "deploy": "ng deploy"
  },
  "engines": {
    "node": "18"
  },
  "main": "server.js",
  "private": true,
  "dependencies": {
    "firebase-frameworks": "^0.6.0",
    "firebase-functions": "^3.23.0",
    "firebase-admin": "^11.0.1"
  }
}
[debug] [2023-04-07T06:16:41.368Z] Building nodejs source
[debug] [2023-04-07T06:16:41.369Z] Could not find functions.yaml. Must use http discovery
[debug] [2023-04-07T06:16:41.369Z] Found firebase-functions binary at '/Users/shibaji/Desktop/project/My Websites/Softwares Techy/.firebase/softwares-techy/functions/node_modules/.bin/firebase-functions'
[debug] [2023-04-07T06:16:41.505Z] Serving at port 8666

[debug] [2023-04-07T06:16:42.537Z] Got response from /__/functions.yaml {"endpoints":{"ssrsoftwarestechy":{"platform":"gcfv2","region":["us-central1"],"labels":{},"httpsTrigger":{},"entryPoint":"ssrsoftwarestechy"}},"specVersion":"v1alpha1","requiredAPIs":[]}
[debug] [2023-04-07T06:16:42.540Z] shutdown requested via /__/quitquitquit

[info] i  functions: Loaded environment variables from .env. 
[info] i  functions: preparing app-apis directory for uploading... 
[info] i  functions: packaged /Users/shibaji/Desktop/project/My Websites/Softwares Techy/app-apis (172.43 KB) for uploading 
[info] i  functions: preparing .firebase/softwares-techy/functions directory for uploading... 
[info] i  functions: packaged /Users/shibaji/Desktop/project/My Websites/Softwares Techy/.firebase/softwares-techy/functions (3.32 MB) for uploading 
[debug] [2023-04-07T06:16:43.016Z] >>> [apiv2][query] GET https://cloudfunctions.googleapis.com/v1/projects/softwares-techy/locations/-/functions [none]
[debug] [2023-04-07T06:16:43.894Z] <<< [apiv2][status] GET https://cloudfunctions.googleapis.com/v1/projects/softwares-techy/locations/-/functions 200
[debug] [2023-04-07T06:16:43.894Z] <<< [apiv2][body] GET https://cloudfunctions.googleapis.com/v1/projects/softwares-techy/locations/-/functions {"functions":[{"name":"projects/softwares-techy/locations/us-central1/functions/api","httpsTrigger":{"url":"https://us-central1-softwares-techy.cloudfunctions.net/api","securityLevel":"SECURE_ALWAYS"},"status":"ACTIVE","entryPoint":"api","timeout":"60s","availableMemoryMb":256,"serviceAccountEmail":"softwares-techy@appspot.gserviceaccount.com","updateTime":"2023-04-05T09:15:03.887Z","versionId":"4","labels":{"deployment-tool":"cli-firebase","firebase-functions-codebase":"app-apis","firebase-functions-hash":"003c65116379cd9e3788d88b8cc0fd5bb65b4a84"},"sourceUploadUrl":"https://storage.googleapis.com/uploads-239769976315.us-central1.cloudfunctions.appspot.com/621351b0-b60c-457d-a12f-7a1804cd62dd.zip","environmentVariables":{"FIREBASE_CONFIG":"{\"projectId\":\"softwares-techy\",\"databaseURL\":\"https://softwares-techy-default-rtdb.asia-southeast1.firebasedatabase.app\",\"storageBucket\":\"softwares-techy.appspot.com\",\"locationId\":\"asia-south1\"}","GCLOUD_PROJECT":"softwares-techy","EVENTARC_CLOUD_EVENT_SOURCE":"projects/softwares-techy/locations/us-central1/functions/api"},"runtime":"nodejs18","ingressSettings":"ALLOW_ALL","buildId":"5b906063-f6bf-45d1-b7f4-e36643bb20c4","buildName":"projects/381317705175/locations/us-central1/builds/5b906063-f6bf-45d1-b7f4-e36643bb20c4","dockerRegistry":"ARTIFACT_REGISTRY"}]}
[debug] [2023-04-07T06:16:43.895Z] >>> [apiv2][query] GET https://cloudfunctions.googleapis.com/v2/projects/softwares-techy/locations/-/functions filter=environment%3D%22GEN_2%22
[debug] [2023-04-07T06:16:45.780Z] <<< [apiv2][status] GET https://cloudfunctions.googleapis.com/v2/projects/softwares-techy/locations/-/functions 200
[debug] [2023-04-07T06:16:45.780Z] <<< [apiv2][body] GET https://cloudfunctions.googleapis.com/v2/projects/softwares-techy/locations/-/functions {"functions":[{"name":"projects/softwares-techy/locations/us-central1/functions/ssrsoftwarestechy","buildConfig":{"build":"projects/381317705175/locations/us-central1/builds/b44c7d0f-1f8f-4b67-b2b3-5eadcd585f72","runtime":"nodejs18","entryPoint":"ssrsoftwarestechy","source":{"storageSource":{"bucket":"gcf-v2-sources-381317705175-us-central1","object":"ssrsoftwarestechy/function-source.zip"}},"sourceProvenance":{"resolvedStorageSource":{"bucket":"gcf-v2-sources-381317705175-us-central1","object":"ssrsoftwarestechy/function-source.zip","generation":"1680760238369378"}}},"state":"FAILED","updateTime":"2023-04-06T05:51:20.845724553Z","labels":{"deployment-tool":"cli-firebase","firebase-functions-codebase":"firebase-frameworks-softwares-techy","firebase-functions-hash":"d591e23f08778bc78e2317ad81095dfd73ea3de2"},"stateMessages":[{"severity":"ERROR","type":"CloudRunServiceNotFound","message":"Cloud Run service projects/softwares-techy/locations/us-central1/services/ssrsoftwarestechy for the function was not found. The function will not work correctly. Please redeploy."}],"environment":"GEN_2"}]}
[debug] [2023-04-07T06:16:46.021Z] TypeError: Cannot read properties of undefined (reading 'service')
    at /Users/shibaji/.nvm/versions/node/v18.15.0/lib/node_modules/firebase-tools/lib/deploy/functions/backend.js:198:113
    at Array.map (<anonymous>)
    at loadExistingBackend (/Users/shibaji/.nvm/versions/node/v18.15.0/lib/node_modules/firebase-tools/lib/deploy/functions/backend.js:198:69)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.existingBackend (/Users/shibaji/.nvm/versions/node/v18.15.0/lib/node_modules/firebase-tools/lib/deploy/functions/backend.js:174:9)
    at async prepare (/Users/shibaji/.nvm/versions/node/v18.15.0/lib/node_modules/firebase-tools/lib/deploy/functions/prepare.js:138:115)
    at async chain (/Users/shibaji/.nvm/versions/node/v18.15.0/lib/node_modules/firebase-tools/lib/deploy/index.js:35:9)
    at async deploy (/Users/shibaji/.nvm/versions/node/v18.15.0/lib/node_modules/firebase-tools/lib/deploy/index.js:79:5)
[error] 
[error] Error: An unexpected error has occurred.

Please help me to solve this problem as soon as possible


Solution

  • You can try downgrading or upgrading @angular/cli. Or

    Try the following commands:

    npm install --save-dev @angular/cli@latest 
    sudo npm install --save-dev @angular/cli@latest -g 
    firebase login
    npm i -D firebase-tools 
    sudo ng add @angular/fire@latest
    

    If you already installed firebase-tools try downgrading it.