Angular 升级后页面加载时出现 Firebase 错误
Firebase errors on page load after Angular upgrade
升级到 Angular13 后,我遇到了身份验证机制的问题。我在 Azure 中使用 Nebular Auth over Firebase 身份验证。当前在页面加载时出现此错误:
zone.js:1063 Unhandled Promise rejection: (0 , tslib__WEBPACK_IMPORTED_MODULE_5__.__rest) is not a function ; Zone: <root> ; Task: Promise.then ; Value: TypeError: (0 , tslib__WEBPACK_IMPORTED_MODULE_5__.__rest) is not a function
at new UserImpl (index-342f2197.js:1599:62)
at Function._fromJSON (index-342f2197.js:1736:22)
at index-342f2197.js:1865:32
at Generator.next (<anonymous>)
at asyncGeneratorStep (asyncToGenerator.js:3:1)
at _next (asyncToGenerator.js:25:1)
at ZoneDelegate.invoke (zone.js:372:1)
at Zone.run (zone.js:134:1)
at zone.js:1276:1
at ZoneDelegate.invokeTask (zone.js:406:1) TypeError: (0 , tslib__WEBPACK_IMPORTED_MODULE_5__.__rest) is not a function
at new UserImpl (http://localhost:4200/vendor.js:5601:60)
at Function._fromJSON (http://localhost:4200/vendor.js:5831:18)
at http://localhost:4200/vendor.js:6008:30
at Generator.next (<anonymous>)
at asyncGeneratorStep (http://localhost:4200/vendor.js:184170:24)
at _next (http://localhost:4200/vendor.js:184192:9)
at ZoneDelegate.invoke (http://localhost:4200/polyfills.js:3497:26)
at Zone.run (http://localhost:4200/polyfills.js:3259:43)
at http://localhost:4200/polyfills.js:4401:36
at ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:3531:31)
起源于firebase-auth.js
。提到的函数也在那里声明:
function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
package.json 摘录:
"dependencies": {
"@angular/animations": "^13.2.1",
"@angular/cdk": "^13.2.1",
"@angular/common": "^13.2.1",
"@angular/compiler": "^13.2.1",
"@angular/core": "^13.2.1",
"@angular/fire": "^7.2.0",
"@angular/forms": "^13.2.1",
"@angular/platform-browser": "^13.2.1",
"@angular/platform-browser-dynamic": "^13.2.1",
"@angular/router": "^13.2.1",
"@nebular/auth": "^9.0.1",
"@nebular/eva-icons": "9.0.1",
"@nebular/firebase-auth": "^9.0.1",
"@nebular/theme": "^9.0.1",
"@ngrx/effects": "^13.0.2",
"@ngrx/entity": "^13.0.2",
"@ngrx/schematics": "^13.0.2",
"@ngrx/store": "^13.0.2",
"@ngrx/store-devtools": "^13.0.2",
"eva-icons": "^1.1.2",
"firebase": "^9.4.0",
(...)
Nebular 使用 Angular Fire 的向后兼容版本(带有兼容包)。
原来问题出在typescript的不必要和不正确的配置上。在 tsconfig.json
路径中我有这条线
tslib" : ["node_modules/tslib/tslib.d.ts"]
并阻止了 tslib
的正确辅助解析。删除我发现不再需要的此设置可以解决问题。
升级到 Angular13 后,我遇到了身份验证机制的问题。我在 Azure 中使用 Nebular Auth over Firebase 身份验证。当前在页面加载时出现此错误:
zone.js:1063 Unhandled Promise rejection: (0 , tslib__WEBPACK_IMPORTED_MODULE_5__.__rest) is not a function ; Zone: <root> ; Task: Promise.then ; Value: TypeError: (0 , tslib__WEBPACK_IMPORTED_MODULE_5__.__rest) is not a function
at new UserImpl (index-342f2197.js:1599:62)
at Function._fromJSON (index-342f2197.js:1736:22)
at index-342f2197.js:1865:32
at Generator.next (<anonymous>)
at asyncGeneratorStep (asyncToGenerator.js:3:1)
at _next (asyncToGenerator.js:25:1)
at ZoneDelegate.invoke (zone.js:372:1)
at Zone.run (zone.js:134:1)
at zone.js:1276:1
at ZoneDelegate.invokeTask (zone.js:406:1) TypeError: (0 , tslib__WEBPACK_IMPORTED_MODULE_5__.__rest) is not a function
at new UserImpl (http://localhost:4200/vendor.js:5601:60)
at Function._fromJSON (http://localhost:4200/vendor.js:5831:18)
at http://localhost:4200/vendor.js:6008:30
at Generator.next (<anonymous>)
at asyncGeneratorStep (http://localhost:4200/vendor.js:184170:24)
at _next (http://localhost:4200/vendor.js:184192:9)
at ZoneDelegate.invoke (http://localhost:4200/polyfills.js:3497:26)
at Zone.run (http://localhost:4200/polyfills.js:3259:43)
at http://localhost:4200/polyfills.js:4401:36
at ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:3531:31)
起源于firebase-auth.js
。提到的函数也在那里声明:
function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
package.json 摘录:
"dependencies": {
"@angular/animations": "^13.2.1",
"@angular/cdk": "^13.2.1",
"@angular/common": "^13.2.1",
"@angular/compiler": "^13.2.1",
"@angular/core": "^13.2.1",
"@angular/fire": "^7.2.0",
"@angular/forms": "^13.2.1",
"@angular/platform-browser": "^13.2.1",
"@angular/platform-browser-dynamic": "^13.2.1",
"@angular/router": "^13.2.1",
"@nebular/auth": "^9.0.1",
"@nebular/eva-icons": "9.0.1",
"@nebular/firebase-auth": "^9.0.1",
"@nebular/theme": "^9.0.1",
"@ngrx/effects": "^13.0.2",
"@ngrx/entity": "^13.0.2",
"@ngrx/schematics": "^13.0.2",
"@ngrx/store": "^13.0.2",
"@ngrx/store-devtools": "^13.0.2",
"eva-icons": "^1.1.2",
"firebase": "^9.4.0",
(...)
Nebular 使用 Angular Fire 的向后兼容版本(带有兼容包)。
原来问题出在typescript的不必要和不正确的配置上。在 tsconfig.json
路径中我有这条线
tslib" : ["node_modules/tslib/tslib.d.ts"]
并阻止了 tslib
的正确辅助解析。删除我发现不再需要的此设置可以解决问题。