Skip to content
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

Can't use some imports from protoplugin with Node16 resolution #586

Closed
paul-sachs opened this issue Oct 11, 2023 · 1 comment · Fixed by #598
Closed

Can't use some imports from protoplugin with Node16 resolution #586

paul-sachs opened this issue Oct 11, 2023 · 1 comment · Fixed by #598

Comments

@paul-sachs
Copy link
Member

paul-sachs commented Oct 11, 2023

@bufbuild/protoplugin/ecmascript exposes some helpers like localName that seem to be untyped when using moduleResolution: Node16 and module: Node16 compiler settings:

image

Trying to compile results in the following error:

../protoplugin/dist/cjs/ecmascript/index.d.ts:6:47 - error TS2307: Cannot find module '@bufbuild/protobuf/dist/cjs/private/names.js' or its corresponding type declarations.

6 export declare const localName: typeof import("@bufbuild/protobuf/dist/cjs/private/names.js").localName, reifyWkt: typeof import("@bufbuild/protobuf/dist/cjs/private/reify-wkt.js").reifyWkt;
                                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../protoplugin/dist/cjs/ecmascript/index.d.ts:6:130 - error TS2307: Cannot find module '@bufbuild/protobuf/dist/cjs/private/reify-wkt.js' or its corresponding type declarations.

6 export declare const localName: typeof import("@bufbuild/protobuf/dist/cjs/private/names.js").localName, reifyWkt: typeof import("@bufbuild/protobuf/dist/cjs/private/reify-wkt.js").reifyWkt;
                                                                                                                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Found 2 errors in the same file, starting at: ../protoplugin/dist/cjs/ecmascript/index.d.ts:6

See reproduction in PR #585.

@timostamm
Copy link
Member

This is an interesting issue. For the ESM exports of @bufbuild/protoplugin, we currently emit a .d.ts file that contains:

export declare const localName: typeof import("@bufbuild/protobuf/dist/cjs/private/names.js").localName

This import cannot be resolved with Node16 module resolution. If we were using Node16 module resolution, we would have gotten a compiler error here:

TS2742: The inferred type of 'localName' cannot be named without a reference to '../../../../node_modules/@bufbuild/protobuf/dist/cjs/private/names.js'. This is likely not portable. A type annotation is necessary.

attw cannot currently catch this kind of issue either, see arethetypeswrong/arethetypeswrong.github.io#45.

We can fix this issue, but we should definitely switch to building ESM with Node16 module resolution to guard against this error class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants