Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Firebase Function Deploy Error: Cannot find module 'firebase/app'

I added SSR on my Angular Firebase Project and also set up WPA. And It successfully deployed on the firebase (hosting and functions). But next time I edited some code in component. After that I'm redeploying. firebase hosting is deploying successfully. But Function showing error.

I'm using Angular 8 and All latest npm packages in package.json I have also updated and rebuild my project. on localhost:5000 everything is fine working.

The error I'm getting: Function failed on loading user code. Error message: Code in file lib/index.js can't be loaded.

     Detailed stack trace: Error: Cannot find module 'firebase/app'
     at Function.Module._resolveFilename (module.js:548:15)
     at Function.Module._load (module.js:475:25)
     at Module.require (module.js:597:17)
     at require (internal/module.js:11:18)
     at webpackUniversalModuleDefinition (/srv/dist/server.js:3:28)
     at Object.<anonymous> (/srv/dist/server.js:10:3)
     at Module._compile (module.js:653:30)
     at Object.Module._extensions..js (module.js:664:10)
     at Module.load (module.js:566:32)
     at tryModuleLoad (module.js:506:12)

and package.json

  "node": "8"
  },
  "main": "lib/index.js",
  "dependencies": {
  "@firebase/app": "^0.4.15",
  "firebase-admin": "^8.0.0",
  "firebase-functions": "^3.1.0"
   },
   "devDependencies": {
   "tslint": "^5.12.0",
   "typescript": "^3.2.2"
  },

and index.js function:

   import * as functions from 'firebase-functions';


   const universal = require(`${process.cwd()}/dist/server`).app;


   export const ssr = functions.https.onRequest(universal);

on cmd: firebase log getting:

   PS C:\Users\DELL\ion\portfolio\portfolio\functions> firebase functions:log
2019-09-02T16:08:55.247320904Z D ssr: Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions
2019-09-02T16:08:55.251Z E ssr: TypeError: handler is not a function
    at cloudFunction (/srv/node_modules/firebase-functions/lib/providers/https.js:49:9)
    at /worker/worker.js:783:7
    at /worker/worker.js:766:11
    at ZoneDelegate.invokeTask (/srv/dist/server.js:581:35)
    at Zone.runTask (/srv/dist/server.js:348:51)
    at ZoneTask.invokeTask (/srv/dist/server.js:663:38)
    at ZoneTask.invoke (/srv/dist/server.js:652:52)
    at data.args.(anonymous function) (/srv/dist/server.js:1603:63)
    at _combinedTickCallback (internal/process/next_tick.js:132:7)
    at process._tickDomainCallback (internal/process/next_tick.js:219:9)
2019-09-02T16:08:55.257867953Z D ssr: Function execution took 11 ms, finished with status: 'crash'
2019-09-02T16:09:14.522Z D ssr: Code in file lib/index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'firebase/app'
    at Function.Module._resolveFilename (module.js:548:15)
    at Function.Module._load (module.js:475:25)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at webpackUniversalModuleDefinition (/srv/dist/server.js:3:28)
    at Object.<anonymous> (/srv/dist/server.js:10:3)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)

I have searched for the solution everywhere but didn't find.

like image 420
Aman Gupta Avatar asked Sep 02 '19 17:09

Aman Gupta


1 Answers

Go inside the /functions directory and run:

$ sudo npm install --save firebase @angular/fire -f   

If it doesn't solve your issue, you can delete node_modules folder in your /functions directory and use my dependencies for

functions/package.json

"dependencies": {
    "firebase-admin": "^8.0.0",
    "firebase-functions": "^3.1.0",
    "@angular/animations": "~8.2.3",
    "@angular/common": "~8.2.3",
    "@angular/compiler": "~8.2.3",
    "@angular/core": "~8.2.3",
    "@angular/fire": "^5.2.1",
    "@angular/forms": "~8.2.3",
    "@angular/platform-browser": "~8.2.3",
    "@angular/platform-browser-dynamic": "~8.2.3",
    "@angular/platform-server": "~8.2.3",
    "@angular/router": "~8.2.3",
    "@ng-bootstrap/ng-bootstrap": "^5.1.0",
    "bootstrap": "^4.0.0-alpha.6",
    "compression": "^1.7.4",
    "firebase": "^6.4.2",
    "rxjs": "~6.4.0",
    "tslib": "^1.10.0",
    "xmlhttprequest": "^1.8.0",
    "zone.js": "~0.9.1"
  }

hit npm install and it should be working when you deploy your app to firebase

like image 136
keser Avatar answered Sep 27 '22 20:09

keser