protobuf.js
protobuf.js copied to clipboard
pbts: Cannot find name 'Long'.
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.
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.
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:
- Re-generate the typescript types with the version of
protobufjs(orprotobufjs-cli) that matches the runtimeprotobufjsversion you are using. - Downgrade your runtime dependency on
protobufjsto match the version used to generate the type definitions. - Add
@types/long: "^4.0.1"to your package.jsondevDependenciessection.
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.