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
Autogenerated code erro: Cannot use namespace 'Long' as a type #2617
Comments
Using Just for the sake of it, I upgraded to typescript latest |
I can't reproduce this with my own generated code with the same version of both proto-loader and TypeScript. Can you create a repository with a complete, self-contained reproduction? |
I started seeing this error once I changed |
Ahhh interesting! Actually this error started occurring in our codebase at the time when we updated our |
https://github.com/davidfiala/badbundle
for errors like
Edit: If I replace in the generated code: |
Worth pointing out that modifying my example above with:
yields
I wonder if it could help to directly import Long from the 'long' library everywhere instead of how it is currently being re-exported from @grpc. I've also seen other projects like |
I also have this issue with module resolution: "Bundler". Going back to "Node" fixes the issue temporarily. That isn't a great fix, though, because "Bundler" is the default module resolution for new RemixJS apps. |
Same problem for newest SveleKit. |
Same problem with firebase-functions! |
I'm going to use the |
Haven't tried this out yet (I'm on mobile) but typescript team announced new improvements to module resolution "Bundler" yesterday in typescript 5.4 need to check if this helps: |
|
I've hit this issue as well and I've done some digging. I believe that I have a better idea of the root cause of the issue. This issue happens when you upgrade from Under the hood, grpc-node/packages/proto-loader/src/index.ts Lines 25 to 27 in d9c2672
I've worked around the issue on my end by downgrading to {
"resolutions": {
"@grpc/proto-loader@npm:0.7.10/long": "5.2.1",
"protobufjs@npm:7.2.5/long": "5.2.1",
"protobufjs@npm:7.2.6/long": "5.2.1"
}
} It feels like the deeper problem is in |
This is necessitated as a fix for [pr5226], due to [grpc-node issue 2617]. [grpc-node issue 2617]: grpc/grpc-node#2617 [pr5226]: #5226
Problem description
The autogenerated type code from
@grpc/grpc-js
is generating code that is not valid typescript.Example Error
For example, the
Long
that is imported causes an error:I edited the autogenerated file by using
typeof Long
further below in the code & that made the typescript error go away.This works because Namespaces can be converted to types using the
typeof
keyword.Reproduction steps
Work in progress
This is what my settings for generating types looks like using @grpc/proto-loader
https://www.npmjs.com/package/@grpc/proto-loader#generating-typescript-types
Environment
OS Name: Sonomo 14.1.1
Node version 20.5.0
Typrscript: 5.0.4
@grpc/grpc-js": "1.9.9",
@grpc/proto-loader": "0.7.10",
The text was updated successfully, but these errors were encountered: