Locker Service Unable to use external scripts

When using:

<ltng:require scripts="x,y,z" afterScriptsLoaded="{!c.onScriptLoaded}/>

In a pre-release version of Spring ’17 with Locker Service enabled, while in the controller method onScriptLoaded, I’m unable to use my external namespace. However, when I debug the included script, I clearly see that window.MyCodeNamepsace and MyCodeNamepsace evaluate to my code at the end of the included script y.
Why can’t I access it using the onScriptLoaded method?

ps: it works flawlessly without Locker Service 😉

What am I doing wrong?

Answer

I’m going to assume that you have checked your browser console log for errors 🙂

Based on my experience, it’s possible that your script is failing silently with LockerService activated. There is probably a method in your script that is behaving differently because of LockerService JS method override. My only recommendation would be to also debug your script and see where your code is failing. It’s a tedious process, unfortunately.

Attribution
Source : Link , Question Author : Marc-Antoine Veilleux , Answer Author : kev_panda

Leave a Comment