observablehq / plot

A concise API for exploratory data visualization implementing a layered grammar of graphics
https://observablehq.com/plot/
ISC License
4.25k stars 173 forks source link

Trouble using Plot library in a CommonJS environment #2041

Closed AlbertIspiryan-dev closed 5 months ago

AlbertIspiryan-dev commented 5 months ago

I'm trying to use the Plot library in a Node.js project, but I'm encountering issues due to the library being distributed as an ES module. Here's the relevant part of my tsconfig.json:

{
  "compilerOptions": {
    "compilerOptions": {
    "rootDir": "./src",
    "outDir": "dist",
    "target": "esnext",
    "module": "commonjs",
    "esModuleInterop": true,
    "sourceMap": true,
    "declaration": true,
    "declarationMap": true,
    "removeComments": true,
    "skipLibCheck": true,
    "noImplicitAny": true,
    "composite": true,
    "noImplicitReturns": true,
    // other options...
  }
}

The error is:

Error [ERR_REQUIRE_ESM]: require() of ES Module C:\path\node_modules\d3\src\index.js from C:\path\packages\libs\dist\jsfile.js not supported.

Usage:

import * as Plot from '@observablehq/plot';