[Bug]:
Would you like to work on a fix?
- [ ] Check this if you would like to implement a PR, we are more than happy to help you go through the process.
Current and expected behavior
I am using Remix Run and wanted to add a simple bar chart using chart.js/react-chartjs-2 into my route: import { Bar } from "react-chartjs-2":
const data = {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [
{
label: "My First dataset",
backgroundColor: "rgba(255,99,132,0.2)",
borderColor: "rgba(255,99,132,1)",
borderWidth: 1,
hoverBackgroundColor: "rgba(255,99,132,0.4)",
hoverBorderColor: "rgba(255,99,132,1)",
data: [65, 59, 80, 81, 56, 55, 40],
},
],
};
export default function Chart() {
return (
<>
<div>
<h2>Bar Example (custom size)</h2>
<Bar
data={data}
width={100}
height={50}
options={{
maintainAspectRatio: false,
}}
/>
</div>
</>
);
}
This error was given when building the page:
The path "react-chartjs-2" is imported in ..\chart.tsx but "react-chartjs-2" was not found in your node_modules. Did you forget to install it?
When go to the route page on the browser, this error was given:
Error: No "exports" main defined in ..\node_modules\react-chartjs-2\package.json
at new NodeError (node:internal/errors:393:5)
at throwExportsNotFound (node:internal/modules/esm/resolve:358:9)
at packageExportsResolve (node:internal/modules/esm/resolve:612:7)
at resolveExports (node:internal/modules/cjs/loader:529:36)
at Function.Module._findPath (node:internal/modules/cjs/loader:569:31)
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:981:27)
at Function.Module._load (node:internal/modules/cjs/loader:841:27)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (..\chart.tsx:2:21)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Function.Module._load (node:internal/modules/cjs/loader:878:12)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18)
Reproduction
Simply create a new Remix project and change the code in the route app\index.tsx as given above.
chart.js version
v4.0.1
react-chartjs-2 version
v5.0.1
Possible solution
No response
@zerot69 Hi. https://react-chartjs-2.js.org/faq/esm-only
@dangreen Hi. I tried that method but still can't solve the problem. Any ideas why?
@zerot69 Please provide repo with reproduction
@dangreen here is the repo of the Remix project
I've downgraded to "chart.js": "^3.9.1" and "react-chartjs-2": "^4.3.1". This works for me now. Not sure what causes the problem with the lastest version but I guess I'll stick with these ver for now
@zerot69 Given project is not ESM
https://github.com/zerot69/remix-chartjs/blob/master/package.json
please read https://react-chartjs-2.js.org/faq/esm-only/