protobufjs / protobuf.js

Protocol Buffers for JavaScript & TypeScript.
Other
9.88k stars 1.41k forks source link

pbts: Cannot find name 'Long'. #1533

Open kherock opened 3 years ago

kherock commented 3 years ago

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.

toteto commented 2 years ago

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.

Goldabj commented 1 year ago

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.