ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

SAP Spartacus RouterModule.forRoot() called twice 的错误消息

2021-06-05 15:04:03  阅读:317  来源: 互联网

标签:main Code dist Spartacus forRoot RouterModule server sony20210526 js


重现方式:

npm install and then yarn dev:ssr
错误消息:

Compiled successfully.
** Anqular Universal Live Development Server is Listening on http://localhost:4201,open your browser 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() instead
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.7

分析

出问题的 homeModule:

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

B2bStorefrontModule 不应该被加载两次,也不应该以懒加载的方式被加载。

但事实上,该 module 被重复加载了多次:

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 里如果想提供配置,建议使用如下方式:

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

如果用户有大量的自定义逻辑,不推荐使用形如 B2cStorefrontModule 的 recipe module, 而是 building individually tailored storefronts by importing only modules that are needed.

并且,b2cStorefrontModule 在 3.x 版本被设置为 deprecated 状态,并且将来会被移除, in favor of a standardized reference structure.

更多Jerry的原创文章,尽在:"汪子熙":

标签:main,Code,dist,Spartacus,forRoot,RouterModule,server,sony20210526,js
来源: https://www.cnblogs.com/sap-jerry/p/14852750.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有