-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
Recently, TypeScript has added a new resolution mode for Node ESM files. This mode is enabled when running with --moduleResolution nodenext
. Under this mode, ESM files respect rules like the exports
field on packages. Any .mts
or .mjs
file is an ES module, and any .ts
and .js
file is ESM if a containing package.json
contains the field "type": "module"
.
When trying to consume highlight.js under this mode, it currently doesn't pick up on the types being shipped. I can't seem to find the package.json
contents that have been shipped on npm (https://unpkg.com/browse/[email protected]/package.json) but this is because each exports
field needs to have its own types
field as well; otherwise, TypeScript will prefer to look for a corresponding .d.ts
file wherever the require
or import
fields point to.
I believe that the correct solution is to provide the following fields in your package.json
.
".": {
"types": "./types/index.d.ts",
"require": "./lib/index.js",
"import": "./es/index.js"
},
"./*" {
"types": "./types/index.d.ts"
}