Skip to content
Source
Sign inSign up
TanStack/react-charts

Error [ERR_REQUIRE_ESM] in 3.0 beta versions and 2.0 beta 7 fails on require('performance-now') #312

Send to my agent
Closedfergusmeiklejohn(GitHub profile, opens in a new tab) opened this issue 2 comments

In a Remix app, I can't use React Charts any more :-(

If I try the 3.0 beta the build fails with:

Error [ERR_REQUIRE_ESM]: require() of ES Module /node_modules/d3-time-format/src/index.js from /node_modules/react-charts/lib/utils/buildAxis.linear.js not supported.
[1] Instead change the require of index.js in /node_modules/react-charts/lib/utils/buildAxis.linear.js to a dynamic import() which is available in all CommonJS modules.

While if I try the 2.0 beta-7 the build fails with:

1] ✘ [ERROR] Could not resolve "performance-now"
[1] 
[1]     node_modules/react-charts/dist/react-charts.development.js:853:20:
[1]       853 │   var now = require('performance-now'),
[1]           ╵                     ~~~~~~~~~~~~~~~~~

Can anyone suggest a workaround? I'm loath to use another charting library, I like React Charts.

  1. Reproduction here: https://github.com/fergusmeiklejohn/rc-esm-bug-demo

    npm i npm run dev navigate to locahost:3000 error logs in server console

  2. the fix is adding serverDependenciesToBundle: ["react-charts", "d3-time-format"], to remix.config.js

    See this in the Remix docs: https://remix.run/docs/en/v1/pages/gotchas#importing-esm-packages

Sign in to join this conversation.