Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does ts-protoc-gen support windows? #15

Closed
YPhyu opened this issue Jul 18, 2017 · 18 comments
Closed

Does ts-protoc-gen support windows? #15

YPhyu opened this issue Jul 18, 2017 · 18 comments

Comments

@YPhyu
Copy link

YPhyu commented Jul 18, 2017

I am trying out grpc-web and grpc-proxy. I am getting error when I try to compile proto to ts.

Error: ts_out: protoc-gen-ts: 1% is not a valid Win32 application.

Thank you for your help in advance.

@delaneyj
Copy link

@YPhyu add .cmd to the end of it and it works (using this locally on a Win10 computer)

@YPhyu
Copy link
Author

YPhyu commented Jul 24, 2017

Thanks. It works fine now.

@YPhyu YPhyu closed this as completed Jul 24, 2017
@bonnyr
Copy link

bonnyr commented Oct 5, 2017

running on windows 7 still not successful:
npm install ts-protoc-gen within the project directory creates a new package directory,
but there's no ts-protoc-gen.cmd file in the bin directory, only ts-protoc-gen (a javascript file without
the extension)

Is the installation on windows supposed to create a separate launcher?

@YPhyu
Copy link
Author

YPhyu commented Oct 6, 2017

@bonnyr the plugin (protoc-gen-ts.cmd not ts-protoc-gen.cmd) is under node_modules\.bin

@bonnyr
Copy link

bonnyr commented Oct 6, 2017

here's my copy of the bin directory (inside the current project):

λ dir ......\node_modules\ts-protoc-gen\bin
Volume in drive E is New Volume
Volume Serial Number is 306C-DC6D

Directory of <project_path>\node_modules\ts-protoc-gen\bin

10/06/2017 01:07 AM

.
10/06/2017 01:07 AM ..
10/05/2017 03:04 PM 57 protoc-gen-js_service
10/05/2017 03:04 PM 49 protoc-gen-ts
2 File(s) 106 bytes
2 Dir(s) 45,089,464,320 bytes free

Am I missing something here?

@YPhyu
Copy link
Author

YPhyu commented Oct 6, 2017

You should look for the plugin at node_modules\.bin rather than Directory of <project_path>\node_modules\ts-protoc-gen\bin

@bonnyr
Copy link

bonnyr commented Oct 6, 2017

My bad - thanks for this. It's working now

@unsafePtr
Copy link

Hi, I am trying to run ts-protoc-gen from PowerShell. I type the following command

$protoc = 'C:\Users\admin\.nuget\packages\google.protobuf.tools\3.5.0\tools\windows_x64\protoc.exe'
$arguments = "--plugin=protoc-gen-ts=.\node_modules\.bin\protoc-gen-ts.cmd --js_out=import_style=commonjs,binary:generated --ts_out=service=true:generated -I .\proto .\proto\Person.proto"
Start-Process $protoc -ArgumentList $arguments -NoNewWindow

And receive the following error generated/: No such file or directory.
I thought that it is probably slash direction problem, cause on windows it's considered to use \. However powershell don't mind in which direction is used space, but probably plugin internally can't resolve paths.
I have changed the direction of splash and there is error:

'.' is not recognized as an internal or external command,
operable program or batch file.
--ts_out: protoc-gen-ts: Plugin failed with status code 1.

Does anyone tried to execute command from powershell. Maybe I'm doing something wrong?

@webdevelopland
Copy link

webdevelopland commented Mar 13, 2018

@unsafePtr
Looks like windows can't use relative path with .\
Try:

--plugin=protoc-gen-ts=%CD%/node_modules/.bin/protoc-gen-ts.cmd

or absolute path:

--plugin=protoc-gen-ts=C:/path/to/project/node_modules/.bin/protoc-gen-ts.cmd

@forconz
Copy link

forconz commented Sep 10, 2021

PROJECT_BIN="./node_modules/.bin"
PROTOC=".\protoc.exe"
PROTO_DIR="proto"
GRPC_OUT=".\src\grpc"

PROTOC_GEN_TS_PATH=".\node_modules\.bin\protoc-gen-ts.cmd"

$PROTOC -I=$PROTO_DIR wechat.proto
--plugin="protoc-gen-ts=${PROTOC_GEN_TS_PATH}"
--js_out=import_style=commonjs,binary:$GRPC_OUT
--ts_out=:$GRPC_OUT \

I used D:\Projects\Test\helloworld\node_modules.bin\protoc-gen-ts.cmd
$ .\build.sh
Missing output directives.
.\build.sh: line 20: --plugin=protoc-gen-ts=D:\Projects\Test\helloworld\node_modules.bin\protoc-gen-ts.cmd: No such file or directory

I used .\node_modules.bin\protoc-gen-ts.cmd
Tao@Tao MINGW64 /d/Projects/Test/helloworld
$ .\build.sh
Missing output directives.
.\build.sh: line 20: --plugin=protoc-gen-ts=.\node_modules.bin\protoc-gen-ts.cmd: No such file or directory

I am so so... build it for one night~~~~

@forconz
Copy link

forconz commented Sep 10, 2021

PROTOC_GEN_TS_PATH="%CD%/node_modules/.bin/protoc-gen-ts.cmd"

Tao@Tao MINGW64 /d/Projects/Test/helloworld
$ .\build.sh
Missing output directives.
.\build.sh: line 21: --plugin=protoc-gen-ts=%CD%/node_modules/.bin/protoc-gen-ts.cmd: No such file or directory

PROTOC_GEN_TS_PATH="%CD%\node_modules\ts-protoc-gen\bin\protoc-gen-ts.cmd"
Tao@Tao MINGW64 /d/Projects/Test/helloworld
$ .\build.sh
Missing output directives.
.\build.sh: line 21: --plugin=protoc-gen-ts=%CD%\node_modules\ts-protoc-gen\bin\protoc-gen-ts.cmd: No such file or directory

Tao@Tao MINGW64 /d/Projects/Test/helloworld
$ .\build.sh
Missing output directives.
.\build.sh: line 21: --plugin=protoc-gen-ts=%CD%/node_modules/ts-protoc-gen/bin/protoc-gen-ts.cmd: No such file or directory

I was falling apart. I wasn't getting any sleep.

@forconz
Copy link

forconz commented Sep 10, 2021

PROTOC=".\\protoc.exe"
PROTO_DIR="proto"
GRPC_OUT=".\\src\\grpc"

$PROTOC -I=$PROTO_DIR wechat.proto \
  --js_out=import_style=commonjs:$GRPC_OUT \
  --grpc-web_out=import_style=typescript,mode=grpcweb:$GRPC_OUT

Tao@Tao MINGW64 /d/Projects/Test/helloworld
$ .\build.sh

Tao@Tao MINGW64 /d/Projects/Test/helloworld
$

3 files were created by build.sh
\helloworld\src\grpc\wechat_pb.d.ts
\helloworld\src\grpc\wechat_pb.js
\helloworld\src\grpc\WechatServiceClientPb.ts
If I used grpc-web, It work well

But I modified it for @improbable-eng/grpc-web and protoc-gen-ts, It can't work
I was very angry with myself for making such a stupid mistake.

@forconz
Copy link

forconz commented Sep 10, 2021

# generates TypeScript declarations (.d.ts files)
# output service definitions as both .js and .d.ts files in the structure required by grpc-web
# output service definitions as both .js and .d.ts files in the structure required by grpc-node
# .//build.sh

PROJECT_BIN="./node_modules/.bin"
# protoc路径
PROTOC=".\\protoc.exe"
# *.proto文件的存放路径
PROTO_DIR="proto"
# Directory to write generated code to (.js and .d.ts files)
GRPC_OUT=".\\src\\grpc"

# Generating TypeScript Definitions for CommonJS modules generated by protoc
# Path to ts-protoc-gen
PROTOC_GEN_TS=".\\node_modules\\.bin\\protoc-gen-ts.cmd"

# Generating gRPC Service Stubs for use with grpc-web
$PROTOC \
    --plugin="protoc-gen-ts=${PROTOC_GEN_TS}" \
    --js_out="import_style=commonjs,binary:${GRPC_OUT}" \
    --ts_out="service=grpc-web:${GRPC_OUT}" \
    -I=$PROTO_DIR wechat.proto

the code above work well

@forconz
Copy link

forconz commented Sep 10, 2021

# generates TypeScript declarations (.d.ts files)
# output service definitions as both .js and .d.ts files in the structure required by grpc-web
# output service definitions as both .js and .d.ts files in the structure required by grpc-node
# .//build.sh

PROJECT_BIN="./node_modules/.bin"
# protoc路径
PROTOC=".\\protoc.exe"
# *.proto文件的存放路径
PROTO_DIR="proto"
# Directory to write generated code to (.js and .d.ts files)
GRPC_OUT=".\\src\\grpc"

# Generating TypeScript Definitions for CommonJS modules generated by protoc
# Path to ts-protoc-gen
PROTOC_GEN_TS=".\\node_modules\\.bin\\protoc-gen-ts.cmd"


# Generating gRPC Service Stubs for use with grpc-node
$PROTOC \
    --plugin="protoc-gen-ts=${PROTOC_GEN_TS}" \
    --js_out="import_style=commonjs,binary:${GRPC_OUT}" \
    --ts_out="service=grpc-node,mode=grpc-js:${GRPC_OUT}" \
    -I=$PROTO_DIR wechat.proto

#the code above work well

@FatimahJay
Copy link

I'm working in nest js on the microservices architecture (grpc) and want to generate ts file from my proto file but when I run the following command on cmd:

protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_out=./ --ts_proto_opt=nestJs=true ./proto/users.proto

I get the following error:

--ts_proto_out: protoc-gen-ts_proto: %1 is not a valid Win32 application.

Kindly help me out.

@richw-kai
Copy link

I'm working in nest js on the microservices architecture (grpc) and want to generate ts file from my proto file but when I run the following command on cmd:

protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_out=./ --ts_proto_opt=nestJs=true ./proto/users.proto

I get the following error:

--ts_proto_out: protoc-gen-ts_proto: %1 is not a valid Win32 application.

Kindly help me out.

I think you need to run the command as:
protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto.cmd --ts_proto_out=./ --ts_proto_opt=nestJs=true ./proto/users.proto

Or you could create a shortcut to ./node_modules/.bin/protoc-gen-ts_proto.cmd from ./node_modules/.bin/protoc-gen-ts_proto on windows machines if youre working with other devs in other environments

@amarwavare
Copy link

I'm working in nest js on the microservices architecture (grpc) and want to generate ts file from my proto file but when I run the following command on cmd:
protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_out=./ --ts_proto_opt=nestJs=true ./proto/users.proto
I get the following error:
--ts_proto_out: protoc-gen-ts_proto: %1 is not a valid Win32 application.
Kindly help me out.

I think you need to run the command as: protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto.cmd --ts_proto_out=./ --ts_proto_opt=nestJs=true ./proto/users.proto

Or you could create a shortcut to ./node_modules/.bin/protoc-gen-ts_proto.cmd from ./node_modules/.bin/protoc-gen-ts_proto on windows machines if youre working with other devs in other environments

Getting this -

'protoc-gen-ts_proto' is not recognized as an internal or external command,
operable program or batch file.
--ts_proto_out: protoc-gen-ts_proto: Plugin failed with status code 1.

@orenkuper
Copy link

orenkuper commented Mar 27, 2024

protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto.cmd --ts_proto_out=./ --ts_proto_opt=nestJs=true ./proto/

try to run it like this:

protoc --plugin=protoc-gen-ts_proto="$(npm root)\.bin\protoc-gen- 
ts_proto.cmd" --ts_proto_out=./ --ts_proto_opt=nestJs=true ./proto/yourfile.proto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants