zoukankan      html  css  js  c++  java
  • SAP Spartacus RouterModule.forRoot() called twice 的错误消息

    重现方式:

    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:Codesony20210526distspartcusstore-servermain. js:115752:15)
    at Object. factory (C:Codesony20210526distspartacusstore-servermain.js:64140:28)
    at R3Injector.hydrate (C:Codesony20210526distspartacusstore-servermain.js:64007:63)
    at R3Injector.get (C:Codesony20210526distspartacusstore-servermain.js:63757:33)
    at injectInjectorOnly (C:Codesony20210526distspartacusstore-servermain.js:49630:33)
    at Module. Dinject (C:Codesony20210526distspartacusstore-servermain.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的原创文章,尽在:"汪子熙":

  • 相关阅读:
    [转]Asp.net中基于Forms验证的角色验证授权
    [转]npm常用命令
    [转]utf8编码引起js输出中文乱码的解决办法
    LEFT JOIN 和 RIGHT JOIN 运算
    [转].NET 数字格式化:忽略末尾零
    [译]Pro ASP.NET MVC 3 Framework 3rd Edition 目录及说明
    微信授权登录
    百度快照更新慢怎么办
    linux爱好者必须掌握的命令,linux基础命令集合
    input输入框只能输入数字、字母相关组合(正则表达式)
  • 原文地址:https://www.cnblogs.com/sap-jerry/p/14852750.html
Copyright © 2011-2022 走看看