所以我在firebase中托管了一个复杂的Angular项目。到目前为止,我一直在进行普通的客户端渲染,最近我进行了SSR并将项目升级到Angular 9版本。当我运行ng build --prod --aot && ng run myproject:server:production
和运行node dist/server/main
时,尝试访问localhost:port
时抛出以下错误。
Error: Can't resolve all parameters for NgLocaleLocalization: (?).
at getUndecoratedInjectableFactory (\MyProject\dist\server\main.js:1:4440360)
at injectableDefOrInjectorDefFactory (\MyProject\dist\server\main.js:1:4441186)
at providerToFactory (\MyProject\dist\server\main.js:1:4442452)
at providerToRecord (\MyProject\dist\server\main.js:1:4438546)
at R3Injector.processProvider (\MyProject\dist\server\main.js:1:4438606)
at provider (\MyProject\dist\server\main.js:1:4438102)
at input.forEach.value (\MyProject\dist\server\main.js:1:4326776)
at Array.forEach ()
at deepForEach (\MyProject\dist\server\main.js:1:4326718)
at R3Injector.processInjectorType (\MyProject\dist\server\main.js:1:4438062)
但是当我只运行ng serve
时,它运行正常,没有任何问题。因此,我怀疑问题出在SSR构建上。直到我切换到Angular 9才出现。Ivy
也可能是原因。但是就我阅读过angular的官方网站而言,我从未在应用程序中的任何地方从NgLocaleLocalization
扩展@angular/common
类。
我也尝试在NgLocalization
中提供app.module
作为提供者,但是即使那样也没有帮助。在Google的任何地方都没有人报告或提及此问题。我还在github repo中创建了一个问题,但是到目前为止,没有人响应。我完全没有选择。
package.json
"dependencies": {
"@agm/core": "^1.1.0",
"@agm/snazzy-info-window": "^1.1.0",
"@angular/animations": "~9.1.2",
"@angular/cdk": "^9.2.1",
"@angular/common": "~9.1.2",
"@angular/compiler": "~9.1.2",
"@angular/core": "~9.1.2",
"@angular/fire": "^5.4.2",
"@angular/forms": "~9.1.2",
"@angular/localize": "^9.1.2",
"@angular/platform-browser": "~9.1.2",
"@angular/platform-browser-dynamic": "~9.1.2",
"@angular/platform-server": "~9.1.2",
"@angular/router": "~9.1.2",
"@ks89/angular-modal-gallery": "^7.2.5",
"@ng-bootstrap/ng-bootstrap": "^6.0.2",
"@nguniversal/express-engine": "^9.1.0",
"@nguniversal/module-map-ngfactory-loader": "8.2.6",
"angular-count-to": "0.0.3",
"angular-tilt": "^1.2.0",
"angular-typing-animation": "^0.5.4",
"animate-scss": "^3.2.1",
"animate.css": "^3.7.2",
"bootstrap": "^4.4.1",
"classlist.js": "^1.1.20150312",
"cookieconsent": "^3.1.1",
"core-js": "^3.6.5",
"express": "^4.17.1",
"firebase": "^7.14.1",
"firebaseui": "4.5.0",
"firebaseui-angular": "^4.1.0",
"hammerjs": "^2.0.8",
"jspdf": "^1.5.3",
"jspdf-autotable": "^3.4.3",
"lodash": "4.17.15",
"moment-timezone": "^0.5.28",
"mousetrap": "^1.6.5",
"ng-animate": "^0.3.4",
"ng2-animate-on-scroll": "^2.0.0",
"ng2-cookies": "^1.0.12",
"ng2-scroll-to-el": "^1.2.1",
"ng5-slider": "^1.2.4",
"ngx-build-plus": "^9.0.6",
"ngx-content-loading": "^0.1.3",
"ngx-cookieconsent": "^2.2.3",
"ngx-logger": "^4.1.5",
"ngx-masonry": "^9.1.1",
"ngx-masonry-gallery": "^3.0.0",
"ngx-owl-carousel-o": "^3.0.0",
"ngx-spinner": "^9.0.2",
"ngx-swiper-wrapper": "^9.0.1",
"ngx-toastr": "^12.0.1",
"razorpay": "^2.0.6",
"rxjs": "^6.5.5",
"rxjs-compat": "^6.5.5",
"snazzy-info-window": "^1.1.1",
"sweetalert2": "^9.10.12",
"tslib": "^1.11.1",
"web-animations-js": "^2.3.2",
"zone.js": "~0.10.3"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.901.1",
"@angular/cli": "^9.1.1",
"@angular/compiler-cli": "~9.1.2",
"@angular/language-service": "~9.1.2",
"@types/express-serve-static-core": "^4.17.5",
"@types/googlemaps": "^3.39.3",
"@types/hammerjs": "^2.0.36",
"@types/jasmine": "~3.5.10",
"@types/jasminewd2": "~2.0.8",
"@types/lodash": "^4.14.149",
"@types/mousetrap": "^1.6.3",
"@types/node": "^13.11.1",
"bufferutil": "^4.0.1",
"codelyzer": "^5.2.2",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~5.0.1",
"karma": "~5.0.2",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~2.1.1",
"karma-jasmine": "~3.1.1",
"karma-jasmine-html-reporter": "^1.5.3",
"localstorage-polyfill": "^1.0.1",
"protractor": "~5.4.4",
"replace-in-file": "^5.0.2",
"serverless-webpack": "^5.3.1",
"ts-loader": "^7.0.0",
"ts-node": "~8.8.2",
"tslint": "~6.1.1",
"typescript": "^3.8.3",
"utf-8-validate": "^5.0.2",
"webpack-cli": "^3.3.11",
"ws": "^7.2.3",
"xhr2": "^0.2.0"
}
知道这个错误实际上是在说什么吗?如何解决这个问题或我还需要尝试什么? :)
非常感谢任何建议/建议/决议。
Update-TBH,我没有在应用中使用本地化,因此从问题发生的地方继续进行调试,然后发现我使用了ng-bootstrap
,这需要包含@angular/localize
软件包。但是,即使在此之后,我也无法获得解决方案。
如果您查看the source code为NgLocaleLocalization
,您会发现它需要LOCALE_ID
令牌
@Injectable()
export class NgLocaleLocalization extends NgLocalization {
constructor(@Inject(LOCALE_ID) protected locale: string) {
super();
}
也许尝试在您的代码中提供此信息
providers: [{provide: LOCALE_ID, useValue: 'en-US' }] //Or any other language
如果可行,则根据需要提供基于工厂的语言环境