I am attempting to use the D3 JavaScript library in a Web Component, but am having issues getting any method to work.

I have downloaded the d3.zip file from the link above, and have attempted to compress both d3.js and d3.min.js with a style.css file provided by trailhead apps git repo for the Use Third Party JS Libraries documentation. And I took the compressed file and uploaded as a Static Resource.

After figuring out that you have to compress the files together, not compress a folder containing the files, in order for the Web Component to be able to load the resources properly, I was finally able to get around a 404 error when attempting to load the needed Script files I want to use (d3.js or d3.min.js).

However, now for every single possible function within this library, I get the error function is not defined. It's as if they JS file was uploaded fine as a resource, and I was able to load the resource fine, but when the resource is loaded, nothing is in it....

Any idea on why salesforce would be able to load the needed resource, but not be able to use the resources functions???

  • Did you import the methods as mentioned in the documentation? – sfdcfox Feb 27 at 1:37
  • It seems you are facing issues with your static resource. As an example, I recreated another component, uploaded a new static resource with the files, referred that in the JS, and exactly copy pasted the JS as in the documentation, and it just works fine. – Jayant Das Feb 27 at 2:36
  • 1
    Turns out that I was trying to use D3 in the initializeD3 method, where you need to use d3. Unfortunately, they don't mention in the documentation that d3 will be marked as not defined if you don't disable that lint protection. – BlondeSwan Feb 27 at 16:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.