Our npm library package, built in TypeScript and known as lib-utils
, provides a range of utilities for other projects to leverage.
One of the dependencies within lib-utils
is d3
, which is both a peerDependency and a devDependency. Additionally, there is a devDependency on @types/d3
.
While not all projects utilizing lib-utils
will require the d3
functionality it offers, some of our source files still import d3
using import * as d3 from "d3"
to ensure compile-time checks. This inadvertently places a runtime requirement on d3
for any upstream project using lib-utils
. The result? 404 errors when trying to load d3
in the browser.
We've attempted various solutions, such as:
/// <reference path="../../node_modules/@types/d3/index.d.ts" />
/// <reference type="d3">
However, we are unable to resolve compilation issues without resorting to the regular module import method, leading to the current dilemma.
Is there a way to maintain TypeScript type checking in lib-utils
without mandating that users provide d3
, especially if they do not intend to use its features?
Our packaging relies on systemjs. While a solution instructing systemjs to overlook d3
could be an option, ideally, we'd like to address this directly within lib-utils
instead of requiring modifications from each individual consumer.