ceifa / tiktoken-node

OpenAI's tiktoken but with node bindings
103 stars 10 forks source link

fix: add `exports.types` field #11

Closed bounoable closed 1 year ago

bounoable commented 1 year ago

Without the types field, "moduleResolution": "NodeNext" does not work:

Could not find a declaration file for module 'tiktoken-node'. '/.../node_modules/tiktoken-node/index.mjs' implicitly has an 'any' type.
  There are types at '/.../node_modules/tiktoken-node/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'tiktoken-node' library may need to update its package.json or typings.ts(7016)
ceifa commented 1 year ago

That is weird, the "types" parameter on package.json shouldn't handle that already?

bounoable commented 1 year ago

It's a bit weird and hidden within the Node docs: https://nodejs.org/api/packages.html#community-conditions-definitions

"types" - can be used by typing systems to resolve the typing file for the given export. This condition should always be included first.

Basically, if a package.json provides an "exports" field, then the root "main", "module", and "types" entries are ignored by TypeScript (with moduleResolution set to "NodeNext").