6

I have an lwc component to display charts using chartjs library in the community. The component was working perfectly in internal salesforce but the chartjs library failed to load in the community.

By trial and error, I found this setting in community builder for Locker service which prevents loading of any script(from static resource) in the community. enter image description here

After disabling this setting the component loads perfectly.

However, I noticed that there is no setting for this in experience bundle JSON(or at least sfdx force:source:pull command doesn't detect it), and every time in a new org I have to manually disable this setting.

I am using community with this template: Build Your Own (LWR)

Is there a different way to disable this setting without manual effort?

Also shouldn't this setting block lwc from different namespace instead of blocking all static resources js files even from the same namespace(strangely it allows CSS files from static resource to load)

1 Answer 1

0

If this is a customer-specific need, Use Chart.js via LWR Public Assets Instead of Static Resources Rather than loading Chart.js from a static resource, consider hosting it in the LWR public assets folder. For example, place chart.min.js under: experiences/mySite/assets/ Then load it using a relative path in your component. These public assets are Locker-compliant in LWR context and should work without issues.

Alternatively, if it's feasible for your use case, you can switch from the LWR template to a different Experience Cloud template where third-party script loading is more flexible.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.