Skip to content

How to fix "Cannot find module 'react-chartjs-2'" error?

Since v6, react-chartjs-2 is an ESM-only package, and the error means that something tries to load it as CommonJS:

  • Node.js before 20.19 and 22.12 cannot require() an ES module: upgrade Node.js, or make your code ESM.
  • Jest runs tests as CommonJS: let it transform the package with transformIgnorePatterns, run it with ES modules support, or use Vitest.

See the migration guide to v6 for the details. If you cannot load ES modules yet, use react-chartjs-2 v5, which ships the CommonJS build.