grpc-node
grpc-node copied to clipboard
"long" types need to be listed as dependency - yarn v2
Problem description
Need to list @types/long
as dependency
Reproduction steps
Typescript build fails when using Yarn v2+ in pnp mode
Environment
- OS name, version and architecture: Arch Linux
- Node version 14.18.2
- Node installation method: nvm
- Package name and version: @grpc/[email protected]
Additional context
Building with yarn and Typescript gives:
error TS2688: Cannot find type definition file for 'long'.
/// <reference types="long" />
I solved it by adding this to my .yarnrc.yml
, which I believe means @types/long
needs to be added as an explicit dependency in this package
packageExtensions:
"@grpc/grpc-js@*":
dependencies:
"@types/long": "*"
I don't understand why it would need that dependency. @grpc/grpc-js
does not import the package long
anywhere. Instead, it imports the type Long
from @grpc/proto-loader
. That package does have a dependency on @types/long
, which it uses to define that type. It should be the case that if a package exports a type and declares whatever dependencies are necessary to define it, that should be sufficient to provide that type.
Since this problem only seems to happen with Yarn's new PnP, I think that is where the problem is, and you should file an issue with Yarn, or with this package, which appears to be where they monkey-patch PnP support into typescript
.
Well, grpc-js references "long" in build\src\generated\google\protobuf\Int64Value.d.ts and more than 10 other files. yarn 2 or 3 report this as
.yarn/cache/@grpc-grpc-js-npm-1.5.3-4edae7a246-19d75ac09e.zip/node_modules/@grpc/grpc-js/build/src/generated/google/protobuf/Int64Value.d.ts:1:23 - error TS2688: Cannot find type definition file for 'long'.
1 /// <reference types="long" />
~~~~
This is not related to yarn pnp.
With nodeLinker node_modules @types/long is pulled in via
>yarn why @types/long
├─ @grpc/proto-loader@npm:0.6.9
│ └─ @types/long@npm:4.0.1 (via npm:^4.0.1)
│
└─ protobufjs@npm:6.11.2
└─ @types/long@npm:4.0.1 (via npm:^4.0.1)
so it doesn't matter that grpc-js doesn't.
I see the line you are referencing now. It was auto-generated by TypeScript, and I don't see a way to make it not generate that. It still seems to me that the basic problem here is an incompatibility between TypeScript and Yarn PnP. TypeScript automatically generates this code referencing indirectly imported packages, and that code seems to work almost everywhere but it fails in Yarn PnP.
This is also a problem for pnpm. I submitted a workaround in #2121.
i was having the same problem using Nest.js while trying to load "@google-cloud/recaptcha-enterprise" library.
i had to manually add @types/long to the dev dependency and now it works fine.
hope this helps.
The fix proposed by @jfirebaugh has been released in version 1.6.9. Please try it out.