Skip to content

Commit 160c2ce

Browse files
committed
docs: add new page to faq
1 parent ef1fe41 commit 160c2ce

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

website/docs/faq/docs.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,8 @@ exports.docs = [
2828
title: 'How to use react-chartjs-2 with TypeScript?',
2929
slug: '/faq/typescript',
3030
},
31+
{
32+
title: 'How to fix "Cannot find module \'react-chartjs-2\'" error?',
33+
slug: '/faq/esm-only',
34+
},
3135
];

website/docs/faq/esm-only.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
slug: /faq/esm-only
3+
---
4+
5+
# How to fix "Cannot find module 'react-chartjs-2'" error?
6+
7+
Chart.js v4 and react-chartjs-2 v5 are [ESM-only packages](https://nodejs.org/api/esm.html). To use them in your project, it also should be ESM:
8+
9+
```json title="package.json"
10+
{
11+
"type": "module"
12+
}
13+
```
14+
15+
If you are experiencing this problem with Jest, you should follow [this doc](https://jestjs.io/docs/ecmascript-modules) to enable ESM support. Or, we can recommend you migrate to [Vitest](https://vitest.dev/). Vitest has ESM support out of the box and [has almost the same API as Jest](https://vitest.dev/guide/migration.html#migrating-from-jest). [Here is our example of migration](https://github.com/reactchartjs/react-chartjs-2/commit/7f3ec96101d21e43cae8cbfe5e09a46a17cff1ef).
16+

0 commit comments

Comments
 (0)