Search code examples
d3.jssapui5sap-fiori

How to avoid own D3 library being overwritten when loading other FLP apps?


I am developing a custom Fiori app (let's call it App1) that uses the thirdparty library D3. I needed the newer version (7.5.0) since the existing sap/ui/thirdparty/d3, that is bundled with OpenUI5, is only at 3.4.12. I did:

  1. Download the d3.js with version 7.5.0.

  2. Save it in my project folder:

    enter image description here

  3. Add the resource to my manifest.json:

    "resources": {
      "js": [
        { "uri": "library/d3.js" }
      ]
    }
    

At first loading of the application, everything works fine. I am able to use version 7.5.0. But when I switch between Fiori apps from the SAP Fiori launchpad (FLP), the D3 library gets overwritten by version 3.4.12.

I tried to load the d3.js version 7.5.0 again when I reopen the App1, but it does not take effect.

How can I retain my D3 version to 7.5.0 even when I navigate to other apps?


Solution

    1. The manifest.json section /sap.ui5/resources/js is deprecated. Remove the section.
    2. Instead, call the sap.ui.loader.config API accordingly:
      • with your own namespace in the shim settings
      • and before the d3 is loaded, e.g., either before this.getRouter().initialize() or even before declaring the UIComponent's list of dependencies in your Component.js.

    Here is an example with more information: https://stackoverflow.com/a/75177939/5846045.