-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript resolves CJS type definitions for ESM code with NodeNext
module resolution
#718
Comments
Hi @haines I dug into this a bit and I was able to recreate as you mentioned. The issue seems to be the two different I know you linked a TypeScript issue above, but I'm not 100% sure it's the same problem. Would you be willing to file an issue on TypeScript's repo and post your repro there to see if they have any feedback or opinion on what's happening? If/when they reply, we can go from there on what the best approach is. |
Hi @smaye81, I think you're right, this is not due to that TypeScript bug. It's because of the I used https://github.com/haines/buf-cjs-esm-ts/tree/check-which-types
So, at runtime, Node loads the TypeScript, however, ignores the In Perhaps the proxy should be re-exporting the ESM types instead? Although, why is the |
We are actually going to be fixing this in a future release of Protobuf-ES (see issue #713). The plan will be to remove the The one difference though was that if I flip-flopped your settings ( This is where things get murky. I really have no idea how TypeScript is resolving these under the various circumstances. That's why it may be worth posting something on their repo to see if there's some fundamental issue with our setup or if this actually is a bug in their resolution logic. |
Nice, makes sense.
Likewise. I have boiled it down to a fairly minimal reproduction (https://github.com/haines/typescript-dual-package-esnext-bundler-nodenext); it doesn't seem to be anything specific to your setup. I've raised microsoft/TypeScript#57553. Maybe mixing |
Great! Nice work on the repro. It looks like they agree it's probably a bug. Will be curious to hear what's going on. |
I believe
@bufbuild/protobuf
(and the other@bufbuild
/@connectrpc
packages, which seem to have a similar setup) are affected by microsoft/TypeScript#50466 - when compiled withNodeNext
module resolution, TypeScript resolves the CJS type definitions, not the ESM ones.I discovered this because it actually causes type errors in a monorepo build where an app with
Bundler
module resolution consumes generated messages from a library withNodeNext
resolution. Even though both projects should be ESM, the library refers to the CJS types for imports from@bufbuild/protobuf
.See https://github.com/haines/buf-cjs-esm-ts for a minimal repro. It produces incompatible type errors between
and
For example,
The text was updated successfully, but these errors were encountered: