Comments (15)
it seems it need path normalization , i already tried to replace paths, but it says module not found .
import { Any } from "./google/protobuf/any";
Managed to compile it with :
import { Any } from "google-protobuf/google/protobuf/any_pb.js";
but don't know if it works or not because i am unable to go past this :
i am trying to migrate from grpc-js
to protobuf-ts
in my NestJS project, using nodejs 14.15.1
with tsconfigs
set to ES2020.
after reading the documentation installed Twirp transport
and added the following call to the server.
const transport = new TwirpFetchTransport({
baseUrl: "0.0.0.0:50052"
});
const client = new ProcessTypeWritesServiceClient(transport);
const payload:CreateProcessTypeInput_GRPC = {
processTypeStatus:input.processTypeStatus
}
const {response} = await client.createProcessTypeGRPC(payload);
console.log("Response! " + response)
but getting :
TypeError: globalThis.Headers is not a constructor at TwirpFetchTransport.unary
thanks
from protobuf-ts.
But when i am running the generator it is generating the import like :
import { Any } from "./google\\protobuf\\any";
Fixed in v1.0.11
from protobuf-ts.
That looks interesting :)
Do you happen to be on Windows?
from protobuf-ts.
yep i am using windows 10
from protobuf-ts.
Ok. I'm pretty sure that this "importPath" has windows path separators (\) that have to be swapped.
But I have to setup a test env to confirm and fix. You'll have to wait a few days...
In the meantime, I can think of two workarounds:
- run protoc in the linux subsystem (WSL)
- replace paths in generated code with search and replace
from protobuf-ts.
import { Any } from "./google/protobuf/any";
That should work. I guess the file is not there?
Use protoc argument '--ts_opt generate_dependencies':
- "generate_dependencies"
By default, only the PROTO_FILES passed as input to protoc are generated,
not the files they import. Set this option to generate code for dependencies
too.
Are you running the twirp transport in nodejs?
This transport requires the fetch API.
globalThis.fetch
,globalThis.Headers
andglobalThis.AbortController
are expected. The transport is tested with the polyfill packages node-fetch andabort-controller
.
from protobuf-ts.
You are right i missed the flag --ts_opt generate_dependencies
i got the any file.
yes i am running it in nodejs, also installed node-fetch and abort-controller
both of them but i have no idea what to do next with them :D because it still says TypeError: globalThis.Headers is not a constructor at TwirpFetchTransport.unary
from protobuf-ts.
Have a look here:
protobuf-ts/packages/twirp-transport/clientcompat/client.ts
Lines 12 to 16 in 7d0855f
And here:
from protobuf-ts.
i tried everything but it seems to fail on me every time. if i don't set Headers
then it is always giving :
TypeError: globalThis.Headers is not a constructor
if uncomment it ,getting the following type errors. did google for it allot but i guess i am the only one getting these :(
error TS2322: Type 'typeof Headers' is not assignable to type '{ new (init?: HeadersInit): Headers; prototype: Headers; }'.
The types of 'prototype.forEach' are incompatible between these types.
Type '(callback: (value: string, name: string) => void) => void' is not assignable to type '(callbackfn: (value: string, key: string, parent: Headers) => void, thisArg?: any) => void'.
Types of parameters 'callback' and 'callbackfn' are incompatible.
37 globalThis.Headers = Headers;
~~~~~~~~~~~~~~~~~~
is there any other way i can send calls to the server ?
from protobuf-ts.
The code snippets in the comments above are part of the CI workflow.
They run on every single commit to this repository, in node js.
They also run every single time I make a release.
Take a step back and get Headers working as expected, see examples here: https://developer.mozilla.org/en-US/docs/Web/API/Headers
The fetch API is nice and node-fetch is an excellent implementation.
Try making some simple requests, then add some custom headers.
Once you have that working, the TypeError is either gone - or you should be confident enough to just do globalThis.Headers = Headers as unknown as any;
This will suppress the TypeError. But if you have some import error or broken node-fetch version, it will not help you at all. So get fetch and Headers running first.
from protobuf-ts.
found out that the problem is not with the node-fetch lib.
The globalThis.Headers = Headers;
is taking me to the nestjs Header const declaration
export declare const Headers: (property?: string) => ParameterDecorator;
and the error is always taking me to this
globalThis.fetch(url, {
--
headers: createTwirpRequestHeader(new globalThis.Headers(), !!opt.sendJson, opt.meta),
--
--
})
now need to find out how do i switch this global for the protobuf-ts.
from protobuf-ts.
Alright the problem with globalThis.Headers = Headers;
is really not a problem but Intellij IDE isn't picking up the TS Typings, the project is working in VSCode perfectly fine.
from protobuf-ts.
I'm using jetbrains IDEs as well. Some times the TypeScript service shows invalid errors. Helps to restart it in this case.
But your issue might have been something else. Glad you solved it.
from protobuf-ts.
Thank you for taking your time :)
For anyone encountering the globalThis.Headers = Headers;
problem in Intellij IDE, can solve it like this:
from protobuf-ts.
// I am using Any type in one of my proto file import "google/protobuf/any.proto";But when i am running the generator it is generating the import like :
import { Any } from "./google\\protobuf\\any";
-
npm install node-fetch
-
npm install abort-controller
-
and --ts_opt generate_dependencies in your cmd
from protobuf-ts.
Related Issues (20)
- unused parameters in the empty.ts are causing TypeScript check errors HOT 6
- Global `Object` is not referenced when there is a message named Object. HOT 2
- Proto2 required fields are not serialized when they are the default value HOT 3
- Is this compiling error could be turned off by Typescript or Option in protobuf-ts HOT 2
- 2.9.2 not working with 'exactOptionalPropertyTypes: true' HOT 1
- Release 2.9.3 breaks serialization for me HOT 6
- Generated message classes cannot be subclassed because of missing 'export' HOT 1
- Error decoding from binary: "cant skip wire type 4" HOT 1
- How to debug INVALID_ARGUMENT? HOT 1
- Missing headers on RPCError HOT 8
- rpcError cannot support Chinese
- [Request] Flag to handle google wrapper types HOT 1
- Vite cannot found module HOT 2
- Invalid typescript in descriptor.ts HOT 2
- Can't retry request after awaiting response HOT 2
- Typesafe API to retrieve enums from strings HOT 4
- `output_javascript` no longer emits `.d.ts` files HOT 6
- Request: Support for moduleResolution "nodenext" and "node16" HOT 2
- Fails to download v27.0-rc1 (which was just released) HOT 7
- invalid url for latest v27.0-rc1 release HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protobuf-ts.