I am using the Visx library to build charts in Nextjs. I am using the Visx scales, for which I import them as follows:
import { scaleBand, scaleLinear, scaleOrdinal } from "@visx/scale"
Internally, Visx uses d3's scales and is using "require" import to access them, so I get the following Nextjs error:
Error: require() of ES Module \node_modules\d3-scale\src\index.js from \node_modules\@visx\scale\lib\scales\band.js not supported. Instead change the require of index.js in \node_modules\@visx\scale\lib\scales\band.js to a dynamic import() which is available in all CommonJS modules.
I know the error is self-explanatory, but I would like to know if there is another solution besides changing the library's files or, in any case, what is the best one.
I also tried changing the imports of Visx scales, but I got another error:
Cannot use import statement outside a module