The shim.ts file makes use of a type-only side-effect import of the
shim.d.ts file, in order to bring in type declarations into scope without
using a triple-slash reference directive. This is all to satisfy the JSR rule
forbidding such directives (and forbidding module augmentation as well).
The only problem is that @deno/dnt currently does not elide the side-effect
import when generating the shim.js file, leading to an unnecessary import at
runtime of the shim.d.ts file.
In older versions of Node this would lead to a syntax error since .d.ts files
are not valid JavaScript modules. Newer versions of Node feature experimental
TypeScript support (through type erasure mostly, or transformation if enabled
and needed e.g. for enums), but still raise an error as Node does not
support handling TypeScript syntax for any files located in node_modules.
TLDR: attempting to use the shim module in any non-local Node.js environment
will lead to runtime errors.
To fix this, I propose switching the import from import "./shim.d.ts"; to
import type {} from "./shim.d.ts"; in shim.ts. This will ensure that the
import is erased as expected during the transpilation step JSR performs, and
should still bring in the type declarations from shim.d.ts as needed.
The
shim.tsfile makes use of a type-only side-effect import of theshim.d.tsfile, in order to bring in type declarations into scope withoutusing a triple-slash reference directive. This is all to satisfy the JSR rule
forbidding such directives (and forbidding module augmentation as well).
The only problem is that
@deno/dntcurrently does not elide the side-effectimport when generating the
shim.jsfile, leading to an unnecessary import atruntime of the
shim.d.tsfile.In older versions of Node this would lead to a syntax error since
.d.tsfilesare not valid JavaScript modules. Newer versions of Node feature experimental
TypeScript support (through type erasure mostly, or transformation if enabled
and needed e.g. for enums), but still raise an error as Node does not
support handling TypeScript syntax for any files located in
node_modules.TLDR: attempting to use the
shimmodule in any non-local Node.js environmentwill lead to runtime errors.
To fix this, I propose switching the import from
import "./shim.d.ts";toimport type {} from "./shim.d.ts";inshim.ts. This will ensure that theimport is erased as expected during the transpilation step JSR performs, and
should still bring in the type declarations from
shim.d.tsas needed.