Skip to content
This repository was archived by the owner on Sep 21, 2023. It is now read-only.

Commit 1d451a3

Browse files
Add 'Module resolution' section
1 parent 23788bb commit 1d451a3

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

node/npm_specifiers.md

+26
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,32 @@ package:
4848
import express from "npm:express@^4.17";
4949
```
5050

51+
### Module resolution
52+
53+
The official TypeScript compiler `tsc` supports different
54+
[moduleResolution](https://www.typescriptlang.org/tsconfig#moduleResolution)
55+
settings. Deno only supports the modern `node16` resolution. Unfortunately many
56+
NPM packages fail to correctly provide types under node16 module resolution,
57+
which can result in `deno check` reporting type errors, that `tsc` does not
58+
report.
59+
60+
If a default export from an `npm:` import appears to have a wrong type (with the
61+
right type seemingly being available under the `.default` property), it's most
62+
likely that the packaged types do not support node16. You can verify this by
63+
checking if the error also occurs with `tsc --module node16` or by consulting
64+
the [Are the types wrong?](https://arethetypeswrong.github.io/) website
65+
(particularly the "node16 from ESM" row).
66+
67+
If you want to use a package that doesn't support TypeScript's node16 module
68+
resolution, you can:
69+
70+
1. Open an issue at the issue tracker of the package about the problem. (And
71+
perhaps contribute a fix :)
72+
2. Use a [CDN](./cdns.md), that rebuilds the packages for Deno support, instead
73+
of an `npm:` identifier.
74+
3. Ignore the type errors you get in your code base with `// @ts-expect-error`
75+
or `// @ts-ignore`.
76+
5177
### Including Node types
5278

5379
Node ships with many built-in types like `Buffer` that might be referenced in an

0 commit comments

Comments
 (0)