Closed kwangure closed 1 year ago
Can you provide an example setup that demonstrates this problem? When I set up a simple project that uses "moduleResolution": "bundler"
(+ strict mode) and has a typescript file using @lezer/common, it compiles without error.
I couldn't initially create a minimial repro with any Lezer package that caused TypeScript to throw an error, but I think I've figured it out now.
If the types and files are "siblings", e.g. index.js
and index.d.ts
, then TypeScript can resolve those without looking up the exports
field. It seems all I needed to do was upgrade my Lezer packages which have now been updated to use "sibling" types. In older versions, for example @lezer/highlight
, the module was at ./dist/index.js
while the types were ./dist/highlight.d.ts
such that TypeScript@^5.0 required the exports field to be defined.
The error is usually something along the lines of:
There are types at '/path/to/package/dist/file.d.ts', but this result could not be resolved when respecting package.json "exports". The 'package' library may need to update its package.json or typings.
Apologies for the spam PRs across several Lezer packages. Populating exports field is not needed for those particular packages.
moduleResolution: "bundler"
is a recent setting added to TypeScript to support bundler setups. It's the setting you should probably be using when bundling code. With this setting TypeScript only searches for types in the exports field of thepackage.json
.It requires the following change:
This is issue is relevent to multiple @lezer packages I'm using.