Make NPM peer dependency with chartjs ^4.0.0 valid
I have chartjs v4 installed but npm warn me about missing peer dependency because of this plugin:
npm WARN [email protected] requires a peer of chart.js@^3.0.0 but none is installed. You must install peer dependencies yourself.
Chartjs awesome clearly state that it is compatible with chartjs 4 and the plugin works with this version.
There should be something wrong with the package configuration of this plugin.
Is it easily fixable?
I have not had any problems but I am using a slightly newer version. The relevant lines from my package.json are:
"canvas": "^2.11.2",
"chart.js": "^4.4.1",
"chartjs-plugin-datalabels": "^2.2.0",
Ok I understood the problem.
You have to fix the version of the plugin to the newer version. Although you are using the "^" wildcard.
The package.json version which is defined (^2.0.0 ) is interpreted as 2.0.0 and not the latest minor release. So the peer dependency is not met. I had to fix the version to the newer one ("^2.2.0").
I just didn't understood why the package.lock was not used to check peer dependencies.
After posting I noticed my package-lock.json has Chart.js at version 4.4.3 so the minor update of that went through the last time I ran an update.
From time to time I run the "ncu" (npm-check-updates) utility to check for any needed updates to package.json. Sometimes though it causes breaking changes when there is a major package update so I use it with care. I just ran it in advisory mode and it tells me there is a Chart.js 4.4.7 update as well as Canvas 3.0.1. I am inclined to update Chart.js immediately but Canvas is going to need a review before I attempt it. Then again everything is working fine so I might just leave it all alone LOL.