import react-chartjs-2 causes a run time error!
See original GitHub issueJust 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:
- Created 2 years ago
- Comments:7
Top 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&
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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks that was helpful. I downgraded chart.js to 2.9.4 and got it to work: npm install chart.js@2.9.4
@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.