lezer-parser/highlight

Could not find a declaration file for module '@lezer/highlight'

Closed this issue · 7 comments

This is a TypeScript error when I try to use @lezer/highlight in an ESM project using TypeScript:

Could not find a declaration file for module '@lezer/highlight'. '/node_modules/@lezer/highlight/dist/index.js' implicitly has an 'any' type.
There are types at '/node_modules/@lezer/highlight/dist/highlight.d.ts', but this result could not be resolved when respecting package.json "exports". The '@lezer/highlight' library may need to update its package.json or typings.

What is your moduleResolution option? nodenext/node16 can be weird like this.

Yes, I'm using nodenext/node16. That's the only way to work with the exports field in a TS project as far as I know.

Is upgrading to TS 5.0 and using "moduleResolution": "bundler" an option for you?

The reason I'm pushing back on this is that I'd have to change the package.json and tag a new release for all my packages (which is a lot of them), and that I'm still confused on what the proper format even looks like (the PR you submitted goes against the recommendations in this page, for example). I'm rather hoping that developments on the TS side will make this annoying requirement go away.

I'm using TS 5.0, but, as I'm building an npm package, this paragraph about "moduleResolution": "bundler" scares me:

On the other hand, if you’re writing a library that’s meant to be published on npm, using the bundler option can hide compatibility issues that may arise for your users who aren’t using a bundler. So in these cases, using the node16 or nodenext resolution options is likely to be a better path.

From my understanding, the ideal solution would be to name the type definition files the same as the source files (index.d.ts and index.d.cts). This way, they don't even need to be mentioned in package.json.

I'm using TS 5.0, but, as I'm building an npm package, this paragraph about "moduleResolution": "bundler" scares me:

I am hoping, given the issues with node16-style resolution, that "bundler" becomes widely used, and the community can avoid the extra cruft in every package.json.

From my understanding, the ideal solution would be to name the type definition files the same as the source files (index.d.ts and index.d.cts). This way, they don't even need to be mentioned in package.json.

That would explain why you only had the issue with this package, and not the others. Attached patch adjust the build process to emit a dist/index.d.ts instead. Does that address the problem for you?

Yes, I updated the file to index.d.ts directly in the node_modules, and the issue was fixed. 👍

Great. I've tagged 1.1.4 with this change.