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

Running into import error when using generated code in React app #3

Closed
pedelman opened this issue Sep 11, 2020 · 3 comments
Closed

Comments

@pedelman
Copy link
Contributor

pedelman commented Sep 11, 2020

Hello @timostamm! Thanks for putting together such a wonderful tool. I've been tinkering with the code and I'm running into a peculiar import error I've been struggling to debug. My goal is to be able to create functional client / interfaces from proto files against a server running scalapb https://scalapb.github.io/json.html.

./src/utils/proto/google/protobuf/wrappers.ts
Attempted import error: 'LongType' is not exported from '@protobuf-ts/runtime'.

I have a pretty specific set up im testing, so next steps are to work on isolating the issue further, but I thought I would ask and see if this is something you have experience with.

Basically my process was to run protobuf-ts against my interfaces monorepo. Once I was happy with the configuration and generated code, I proceeded to copy the generated files into a local project in src/utils/proto.

npx protoc --ts_out protobuf-ts --ts_opt long_type_string --ts_opt disable_service_client --ts_opt generate_dependencies --proto_path proto ...

In the package json, I have the following:

    "@protobuf-ts/plugin": "^1.0.3",
    "@protobuf-ts/runtime": "^1.0.3",

I verified in node_modules that I see LongType is exported from runtime types.

$ cat node_modules/\@protobuf-ts/runtime/build/types/index.d.ts

...
export { ScalarType, LongType, RepeatType, MessageInfo, EnumInfo, FieldInfo, PartialFieldInfo, normalizeFieldInfo, readFieldOptions } from './reflection-info';
...

I notice that in src/utils/proto/google/protobuf/wrappers.ts, the LongType import is also the first import, so I doubt this has anything to do specifically with that type.

Some info on node / yarn version.

$ node -v
v12.18.3

$ npm -v
6.14.6

$ yarn -v
1.21.1

If I find the solution, I will be sure to update this. Thanks again!

@pedelman
Copy link
Contributor Author

This seems related to vercel/next.js#7882

@timostamm
Copy link
Owner

Hey @pedelman, I think so too. Specifically, compiler option "isolatedModules" breaks const enums. See facebook/create-react-app#5738

This is a bummer, because const enums are great for small code size. Working on a patch...

@timostamm
Copy link
Owner

Thanks for the excellent report, @pedelman.

If you update to 1.0.4, the issue should be fixed.

scalapb looks like a very nice protobuf implementation. In the long term (when you have more than a handful RPC methods), I would recommend having a look at gRPC-web or Twirp.

Cheers!

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

No branches or pull requests

2 participants