SAP Spartacus RouterModule.forRoot() called twice 的錯誤消息

重現方式:git

npm install and then yarn dev:ssr
錯誤消息:github

Compiled successfully.
Anqular Universal Live Development Server is Listening on http://localhost:4201
ERROR Error: Uncaught (in promise): Error: RouterModule.forRoot() called twice. Lazy Loaded modules should use RouterModule.forChild() instead.
Error: RouterModule.forRoot() called twice. Lazy Loaded modules should use RouterModule.forChild() insteadnpm

at Object.provideForRootGuard [as useFactory] (C:\Code\sony20210526\dist\spartcusstore-server\main. js:115752:15)
at Object. factory (C:\Code\sony20210526\dist\spartacusstore-server\main.js:64140:28)
at R3Injector.hydrate (C:\Code\sony20210526\dist\spartacusstore-server\main.js:64007:63)
at R3Injector.get (C:\Code\sony20210526\dist\spartacusstore-server\main.js:63757:33)
at injectInjectorOnly (C:\Code\sony20210526\dist\spartacusstore-server\main.js:49630:33)
at Module. Dinject (C:\Code\sony20210526\dist\spartacusstore-server\main.js:49640:57)

SAP Spartacus 版本號: 2.1.7promise

分析

出問題的 homeModule:
app

HomeModule is importing B2cStorefrontModule, which shouldn't be imported twice in any scenario, especially shouldn't be lazy-loaded.

B2bStorefrontModule 不該該被加載兩次,也不該該以懶加載的方式被加載。ide

但事實上,該 module 被重複加載了屢次:ui

Any lazy-loaded module should only import the most necessary modules to avoid additional performance impact, and it's especially important for recipe modules like B2cStorefrontModule (the complete b2c storefront recipe).

Custom Module 裏若是想提供配置,建議使用以下方式:spa

ConfigModule.withConfig() or provideConfig utility/#page-title).

若是用戶有大量的自定義邏輯,不推薦使用形如 B2cStorefrontModule 的 recipe module, 而是 building individually tailored storefronts by importing only modules that are needed. ssr

而且,b2cStorefrontModule 在 3.x 版本被設置爲 deprecated 狀態,而且未來會被移除, in favor of a standardized reference structure. code

更多Jerry的原創文章,盡在:"汪子熙":

相關文章
相關標籤/搜索