I am trying to sets up a chart using the Chart.js library, which is uploaded as a static resource, I am getting the below error:

ReferenceError: require is not defined throws at https://karima-dev-ed.lightning.force.com/auraFW/javascript/aJdnlGe7HlLtzbzu8ssZ-A/aura_prod.js line 24 > eval:16:5

<ltng:require scripts="{!$Resource.chart}" afterScriptsLoaded="{!c.setup}"/>
  <canvas aura:id="chart" id="myChart" width="400" height="400"/> 

setup : function(component, event, helper) { 
  var data = { 
    labels: ["January", "February", "March"], 
    datasets: [{ data: [65, 59, 80, 81, 56, 55, 40] }] 
  var el = component.find("chart").getElement(); 
  var ctx = el.getContext("2d"); 
  var myNewChart = new Chart(ctx).Line(data); 
  • 2
    In the future, please edit your question if you have additional stuff to add, like code.
    – sfdcfox
    Apr 13 '18 at 14:10

It sounds like you need require.js. You'll need to download the minified version, upload it, and then include both of them:

<ltng:require scripts="{!join(',',$Resource.requireJS, $Resource.chart)}" ...

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.