Skip to content

Migration to v6

v6 ships only the ES module build: the CommonJS build is gone. The components, their props and the event helpers did not change.

The package has a single entry, dist/index.js, which is an ES module. How your project loads it depends on the tool:

  • Bundlers (Vite, webpack 5, Rollup, esbuild, Parcel) and frameworks built on them, such as Next.js, import ES modules as they are: nothing to change.

  • Node.js 20.19, 22.12 and later can require() an ES module, so server-side rendering from CommonJS keeps working there. Older Node.js versions need your code to be ESM, "type": "module" in package.json, or a dynamic import().

  • Jest runs tests as CommonJS: either let it transform the package,

    jest.config.js
    export default {
    transformIgnorePatterns: ['node_modules/(?!(react-chartjs-2)/)']
    }

    or run Jest with ES modules support, or move the tests to Vitest, which runs ES modules natively.

If none of that is possible yet, keep using react-chartjs-2 v5, which ships the CommonJS build.

The types are published for ES modules only. With "moduleResolution": "node16" or "nodenext" in a CommonJS project, TypeScript asks to import the package with import(): use "moduleResolution": "bundler" when a bundler builds the project, or make the project ESM.