I cannot seem to get a component to load even a basic static resource script when Locker Service is active in a Winter preview sandbox. It works fine if Locker Service is deactivated. Otherwise, I get the following error. What am I doing wrong?

Something has gone wrong. Action failed: c$LockerTestComp$controller$doInit [lockerTest is not defined] Failing descriptor: {c$LockerTestComp$controller$doInit}. Please try again.


<apex:page >
    <apex:includeLightning />
    <div id="lightning"></div>
    <script type="text/javascript">
    $Lightning.use("c:LockerTestApp", function() {
        $Lightning.createComponent('c:LockerTestComp', {}, "lightning", function(cmp) { });


<aura:application extends="ltng:outApp" >


<aura:component >
    <ltng:require scripts="{!$Resource.LockerTest}" afterScriptsLoaded="{!c.doInit}" />
    Hello World


    doInit : function(component, event, helper) {

LockerTest.js (static resource)

var lockerTest = function() {
    alert('it worked');

var lockerTest= is not creating a global method - its a local variable not in the scope of the doInit method. Strict mode removes the creation of automatic globals and you simply need to indicate your intent is to actually create a globally visible function using window.lockertest=

Please see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode for more details on strict mode and global variables.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.