5

我在我的 Angular Firebase 项目中添加了 SSR,还设置了 WPA。并且它成功地部署在了 firebase(托管和功能)上。但是下次我在组件中编辑了一些代码。之后我正在重新部署。firebase 托管正在成功部署。但功能显示错误。

我在 package.json 中使用 Angular 8 和所有最新的 npm 包我还更新并重建了我的项目。在 localhost:5000 上一切正常。

我得到的错误:加载用户代码时函数失败。错误消息:文件 lib/index.js 中的代码无法加载。

     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)

和 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"
  },

和 index.js 函数:

   import * as functions from 'firebase-functions';


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


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

在 cmd:firebase 日志获取:

   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)

我到处寻找解决方案,但没有找到。

4

1 回答 1

5

进入/functions目录并运行:

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

如果它不能解决您的问题,您可以删除目录中的 node_modules 文件夹/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"
  }

命中npm install,当您将应用程序部署到 Firebase 时它应该可以工作

于 2019-09-02T18:34:55.913 回答