0

Some background info: I have small project using d3.js lib in vanilla JS and trying to remake it on TypeScript without any frameworks (React, Vue etc.).

package.json look:

{
  "dependencies": {
    "d3": "^7.6.1",
    "g": "^2.0.1"
  },
  "devDependencies": {
    "@types/d3": "^7.4.0",
    "@types/d3-hierarchy": "^3.1.0",
    "live-server": "^1.2.2",
    "typescript": "^4.8.4"
  }
}

I have an error like Property 'scaleLinear' does not exist on type 'typeof d3'.ts(2339) only with scaleLinear, scaleBand and histogram. Here is code snippet:

const xScale = d3.scaleLinear()
        .domain(d3.extent(dataset, metricAccessor))
        .range([0, dimensions.boundedWidth]);

    const binsGenerator = d3.histogram()
        .domain(xScale.domain())
        .value(metricAccessor)
        .thresholds(10);

At the moment when I added line import * as d3 from 'd3'; into my ts-code, I had error in browser console: Uncaught ReferenceError: exports is not defined

What am I missing or doing wrong?

Dmitry
  • 361
  • 6
  • 21
  • 1
    This looks much like the problem I had. The only answer I found is https://stackoverflow.com/a/71544906/2954288. Check also the respective question. If you think it is the right answer, you could consider flagging your question as a duplicate. – Harald Oct 08 '22 at 06:14

0 Answers0