protobuf.js icon indicating copy to clipboard operation
protobuf.js copied to clipboard

pbts: Cannot find name 'Long'.

Open kherock opened this issue 4 years ago • 1 comments

protobuf.js version: 6.10.2

This issue has been reported multiple times in #1104 #1071 #940 but were all closed with #1166. However that PR was reverted and never made it into a release. As of today, it seems like any definition file generated by pbts that references a Long type is invalid.

kherock avatar Jan 12 '21 17:01 kherock

Any updates on this issue? Are we doing something wrong that working with Long is impossible for static-module?

Using #940 gave me some hope... but it doesn't work for me.

antonio-ivanovski avatar May 28 '22 21:05 antonio-ivanovski

I've run into the same issue. I was able to figure out the root cause was that I had a dependency on a library which had a types.d.ts file generated using pbts and used protobufjs v6.11.2. But my package has a dependency on protobufjs v7.2.2.

In v7 of protobufjs, they removed @types/long and instead use long directly. However, this requires a import Long from 'long' in the generated types.d.ts file. (See the fix in v7 here). Therefore if you import a type.d.ts file without this import (which is missing on older protobufjs version generated files), then the resolution of Long fails (if using v7 protobufjs).

Your options are:

  1. Re-generate the typescript types with the version of protobufjs (or protobufjs-cli) that matches the runtime protobufjs version you are using.
  2. Downgrade your runtime dependency on protobufjs to match the version used to generate the type definitions.
  3. Add @types/long: "^4.0.1" to your package.json devDependencies section.

I went with option 3, since I depend on a handful of pbts generate packages (some on v6, others using v7) which I needed to migrate to v7 iteratively.

Goldabj avatar Mar 15 '23 17:03 Goldabj