react-chartjs-2: Can not resolve chart.js

ERROR in ./~/react-chartjs-2/lib/index.js
Module not found: Error: Can't resolve 'chart.js' in 'node_modules/react-chartjs-2/lib'

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 24
  • Comments: 15

Most upvoted comments

chart.js is a peer dependancy. make sure you include a version in your package.json yourself

Don’t install chartjs like I did! Make sure to:

npm i chart.js

https://www.npmjs.com/package/chart.js?activeTab=readme

npm install --save chart.js This worked for me.

In case you’re facing the issue

Failed to compile. ./node_modules/react-chartjs-2/es/index.js Module not found: Can’t resolve ‘chart.js’

In React I solved this by using npm i chart.js

Apparently even though it’s referred on package.json you have to install it individually

just restart the server. that’s worked for me

npm i chart.js NOT WORKED 😦

But

yarn add chart.js WORKED! 😃

It’s like 2*2=5 But 2+2=4 😐

Don’t forget that too use the library in your react project you should import it this way: import { Pie } from "react-chartjs-2"; And not import { Pie } from "@reactchartjs/react-chart.js"; // This import is used for the examples files only 😉

if npm install chart.js gives error just do npm i chart.js --legacy-peer-deps

just restart the server. that’s worked for me

This not work.

update npm to the latest version, then install chart.js again. if still not working then clear cache from Appdata roaming.