我在 firebase 中托管了一个 Angular 应用。我正在将它上传到 Google Cloud Run。正在创建容器,但一旦服务运行,我收到错误:Cloud Run 错误:容器无法启动。无法启动然后侦听 PORT 环境变量定义的端口。
日志给出错误:globalThis is not defined。
我使用 npm 安装了 globathis 并将其添加到 polyfills.ts 作为第一次导入,如下所示。我也尝试过使用 ungap global this。在此之后,我再次创建了容器并刷新了服务,但收到相同的错误
import '@ungap/global-this';
import 'globalthis/auto';
import 'zone.js/dist/zone'; // Included with Angular CLI.
这是我在日志中得到的:
ReferenceError: globalThis is not defined
at Module.<anonymous> (/usr/src/app/dist/topicos/server/main.js:168651:1)
at Module.jmUF (/usr/src/app/dist/topicos/server/main.js:168726:30)
at __webpack_require__ (/usr/src/app/dist/topicos/server/main.js:26:30)
at Object.ZAI4 (/usr/src/app/dist/topicos/server/main.js:134936:16)
at __webpack_require__ (/usr/src/app/dist/topicos/server/main.js:26:30)
at Object.24aS (/usr/src/app/dist/topicos/server/main.js:42119:22)
at __webpack_require__ (/usr/src/app/dist/topicos/server/main.js:26:30)
at Object.K011 (/usr/src/app/dist/topicos/server/main.js:98994:27)
at __webpack_require__ (/usr/src/app/dist/topicos/server/main.js:26:30)
at Object.uj+Y (/usr/src/app/dist/topicos/server/main.js:188144:23)
以下角度和包版本作为参考:
Angular CLI: 11.0.7
Node: 14.17.3
OS: darwin x64
@angular-devkit/architect 0.1100.7
@angular-devkit/build-angular 0.1100.7
@angular-devkit/core 11.0.7
@angular-devkit/schematics 11.0.7
@angular/cdk 11.2.13
@angular/cli 11.0.7
@angular/fire 6.1.5
@angular/material 11.2.13
@nguniversal/builders 11.2.1
@nguniversal/express-engine 11.0.1
@schematics/angular 11.0.7
@schematics/update 0.1100.7
rxjs 6.6.7
typescript 4.0.8