react-chartjs icon indicating copy to clipboard operation
react-chartjs copied to clipboard

Cannot read property 'Chart' of undefined

Open donnrri opened this issue 9 years ago • 12 comments

Hi,

I cannot find many details as to why I am getting an error when trying to render a chart using react-chartjs. I'm using react v0.13 and webpack. I use the following code :

var LineChart = require("react-chartjs").Line; var React = require('react');

var LChart = React.createClass({

propTypes: { data: React.PropTypes.object }, render: function() {

return <LineChart data={this.props.data} options={this.props.options} width="600" height="250"/>

} });

module.exports = LChart;

but when I use this component within my app I get the error Cannot read property 'Chart' of undefined line 10 Chart.js . Is this a commonly found error and I am missing the solution somewhere ? Thanks for any comments

donnrri avatar Mar 31 '16 09:03 donnrri

Did you specifically run "npm install chart.js" in your terminal when you installed react-chartjs?

danmolitor avatar Apr 01 '16 02:04 danmolitor

I installed the chart.js, but the problems still exist

Qquanwei avatar Apr 05 '16 08:04 Qquanwei

Make sure you install npm install chart.js --save not npm install chartjs --save I did that myself and got that error, realizing the package was wrong when trying to manually adjust it in the module.

hydrotik avatar Apr 08 '16 22:04 hydrotik

I'm receiving this same error Uncaught TypeError: Cannot read property 'Chart' of undefined with chart.js@^1.1.1 installed. Any ideas?

JamieDixon avatar Apr 30 '16 09:04 JamieDixon

same problem here

jbarata avatar May 10 '16 11:05 jbarata

++ @jhudson8

yeliex avatar May 13 '16 07:05 yeliex

Same issue. Excluding node_modules from babel-loader fixed it.

module: {
    loaders: [
      {
        test: /\.jsx?$/,
        exclude: /(node_modules)/,
        loader: 'babel-loader'
      }
    ]
  }

nickstanish avatar Jun 06 '16 20:06 nickstanish

+1

BabOuDev avatar Jun 19 '16 13:06 BabOuDev

+1

Baluhariharan avatar Jul 03 '16 12:07 Baluhariharan

I had the same problem, but as @nickstanish suggested in his response, node_modules exclusion in Webpack solved this. Thanks.

jakubkoci avatar Jul 11 '16 12:07 jakubkoci

Thanks @nickstanish works for me!

emirdeliz avatar Oct 11 '16 17:10 emirdeliz

In my case was the incorrect version installed 1.1. should be ^2.

UPDATE: The error was quite different Cannot read property 'bar' of undefined

ismatim avatar Jan 24 '18 12:01 ismatim