question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

import react-chartjs-2 causes a run time error!

See original GitHub issue

Just started working with React and React version of ChartJS. Got a runtime error as soon as I added the import statement: import { Bar } from 'react-chartjs-2';

  • I created a new app using create-react-app
  • I installed react-chartjs-2 per installation instructions
  • created a new component BarChart and added the above import statement.
  • BarChart component is added to App
  • following runtime error is returned:

I am not sure what this error means?


TypeError: Cannot read property ‘defaults’ of undefined (anonymous function) C:/Users/afshin/react_apps/chartjs/node_modules/react-chartjs-2/es/index.js:643 640 | }(_react[“default”].Component); 641 | 642 | exports.Scatter = Scatter;

643 | var defaults = _chart[“default”].defaults; 644 | exports.defaults = defaults;

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
afshinmoshreficommented, Apr 6, 2021

Thanks that was helpful. I downgraded chart.js to 2.9.4 and got it to work: npm install chart.js@2.9.4

0reactions
afshinmoshreficommented, May 28, 2021

@YakovlevCoded there is an issue with the new react-chartjs-3 that was not a problem with the older version. If a component with a chart is invoked without data changing, chartJS should not render it again. in version 2 this is working fine but in version 3 the chart redraws with the same data when data hasn’t changed. this is causing an undesireable effect on my application that chart redraws the old data and then redraws with new data.

Read more comments on GitHub >

github_iconTop Results From Across the Web

why am I getting a runtime error by importing react-chartjs-2
I'm new to React. I'm trying to use charjs as a react component. ... The component compiles and causes the above error? ......
Read more >
Error Can't resolve 'react-chartjs-2&#38
I get this error. export 'HorizontalBar' (imported as 'HorizontalBar') was not found in 'react-chartjs-2'. Help me fix this ASAP.
Read more >
Chart.js
js renders chart elements on an HTML5 canvas unlike several other, mostly D3.js-based, charting libraries that render as SVG. Canvas rendering ...
Read more >
5 Easy Steps to Implement ChartJS in A React Environment
Run npm install react-chartjs-2 chart.js in your project folder. ... 2. Import the library in the component where you plan to display the...
Read more >
How to Read React Errors (fix 'Cannot read property of ...
This error usually means you're trying to use .map on an array, but that array isn't defined yet. That's often because the array...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found