NestJs Angular 通用不工作 - 启用离线持久性时出错

NestJs Angular Universal Not Working - Error enabling offline persistence

我在使用最新版本的 angular、angularfire 和 angular universal 时遇到此错误。

ng serve

正常发球没问题...

ng add @nestjs/ng-universal

添加了通用,安装似乎很好...

npm run build:ssr

似乎可以编译,但有一些警告,但没有错误...

npm run serve:ssr

似乎一直有效,直到我在本地主机上加载页面并出现此错误:

Error enabling offline persistence. Falling back to persistence disabled: Error: ENOENT: no such file or directory, open 'C:\angular projects\testProject\dist\testproject\server\src\protos\google\firestore\v1\firestore.proto'

----------更新------------

我删除了 dist 文件夹并重新构建,现在我得到这个错误:

Error: ENOENT: no such file or directory, open 'google/protobuf/api.proto'

这是完整的错误:

PS C:\angular projects\testapp.io> npm run serve:ssr

> testapp@0.0.0 serve:ssr C:\angular projects\testapp.io
> node dist/testapp/server/main.js

C:\angular projects\testapp.io\dist\testapp\server\main.js:1
!function(e,a){for(var i in a)e[i]=a[i]}(exports,function(modules){var installedModules={},installedChunks={1:0};function __webpack_require__(moduleId){if(installedModules[moduleId])return installedModules[moduleId].exports;var module=installedModules[moduleId]={i:moduleId,l:!1,exports:{}};return modules[moduleId].call(module.exports,module,module.exports,__webpack_require__),module.l=!0,module.exports}return __webpack_require__.e=function requireEnsure(chunkId){if(0!==installedChunks[chunkId]){var chunk=require("./"+({0:"firebase-functions",2:"vendors~firebase-auth",3:"vendors~firebase-functions"}[chunkId]||chunkId)+".js"),moreModules=chunk.modules,chunkIds=chunk.ids;for(var moduleId in moreModules)modules[moduleId]=moreModules[moduleId];for(var i=0;i<chunkIds.length;i++)installedChunks[chunkIds[i]]=0}return Promise.all([])},__webpack_require__.m=modules,__webpack_require__.c=installedModules,__webpack_require__.d=function(exports,name,getter){

Error: ENOENT: no such file or directory, open 'google/protobuf/api.proto'
    at Object.openSync (fs.js:443:3)
    at Object.readFileSync (fs.js:343:35)
    at fetch (C:\angular projects\testapp.io\dist\testapp\server\main.js:1:1329786)
    at Root.load (C:\angular projects\testapp.io\dist\testapp\server\main.js:1:1330192)
    at Root.loadSync (C:\angular projects\testapp.io\dist\testapp\server\main.js:1:1330372)
    at Object.loadSync (C:\angular projects\testapp.io\dist\testapp\server\main.js:1:2416566)
    at Object.8ZNE (C:\angular projects\testapp.io\dist\testapp\server\main.js:1:1845817)
    at __webpack_require__ (C:\angular projects\testapp.io\dist\testapp\server\main.js:1:317)
    at Object.BYZf (C:\angular projects\testapp.io\dist\testapp\server\main.js:1:1943982)
    at __webpack_require__ (C:\angular projects\testapp.io\dist\testapp\server\main.js:1:317)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! testapp@0.0.0 serve:ssr: `node dist/testapp/server/main.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the testapp@0.0.0 serve:ssr script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\jdgam\AppData\Roaming\npm-cache\_logs20-04-14T06_52_22_707Z-debug.log
PS C:\angular projects\testapp.io> 

所以事实证明它与 Angular 中的 Ivy 有关 9. 确保将 @firebase/firestore 添加到 externalDependencies,因为显然它需要手动导入:

        "server": {
          "builder": "@angular-devkit/build-angular:server",
          "options": {
            "outputPath": "dist/fireblog/server",
            "main": "server.ts",
            "tsConfig": "tsconfig.server.json",
            "externalDependencies": [
              "@firebase/firestore",
              "@nestjs/microservices",
              "@nestjs/microservices/microservices-module",
              "@nestjs/websockets",
              "@nestjs/websockets/socket-module",
              "cache-manager"
            ]
          },

https://github.com/angular/angularfire/issues/2320