thesayyn / protoc-gen-ts

Compile protocol buffer messages to TypeScript.
MIT License
360 stars 74 forks source link

Typescript 4.8.2 support #170

Closed Yurzel closed 1 year ago

Yurzel commented 2 years ago

Typescript version 4.8.2 just got released. There is deprecated function used in the plugin.

Functions: createParameterDeclaration

Error:

TypeError: Invalid arguments
    at Object.createParameterDeclaration (/usr/local/lib/node_modules/@domain/protoc-gen-ts/node_modules/typescript/lib/typescript.js:170461:19)
    at createParameter (/usr/local/lib/node_modules/@domain/protoc-gen-ts/src/rpc.js:154:23)
    at Object.createGrpcInterfaceType (/usr/local/lib/node_modules/@domain/protoc-gen-ts/src/rpc.js:161:31)
    at Object.<anonymous> (/usr/local/lib/node_modules/@domain/protoc-gen-ts/src/index.js:54:32)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
    at Module.load (node:internal/modules/cjs/loader:1004:32)
    at Function.Module._load (node:internal/modules/cjs/loader:839:12)
    at Module.require (node:internal/modules/cjs/loader:1028:19)
    at require (node:internal/modules/cjs/helpers:102:18)
--ts_out: protoc-gen-ts: Plugin failed with status code 1.

According the line 170461 in typescript package it seems like the function was removed completly.

// Deprecations fall into one of three categories:
//
// - "soft" - Soft deprecations are indicated with the `@deprecated` JSDoc Tag.
// - "warn" - Warning deprecations are indicated with the `@deprecated` JSDoc Tag and a diagnostic message (assuming a compatible host).
// - "error" - Error deprecations are either indicated with the `@deprecated` JSDoc tag and will throw a `TypeError` when invoked, or removed from the API entirely.
stannedelchev commented 2 years ago

@thesayyn This is happening on my end too with the latest TypeScript 4.8.3. Installed protoc-gen-ts with npm -g install protoc-gen-ts and then ran protoc -I=. hello.proto --ts_out=. Error call stack is same as post above. Other protobuf compilers (Go, JS) work fine on the same .proto file.

hello.proto:

syntax = "proto3";

service HelloWorld {
    rpc SayHello (HelloRequest) returns (HelloResponse) {}
}

message HelloRequest {
    string Name = 1;
}

message HelloResponse {
    string Message = 1;
}

Error call stack is the same as previous post:

/usr/lib/node_modules/protoc-gen-ts/node_modules/typescript/lib/typescript.js:170487
            throw new TypeError("Invalid arguments");
            ^

TypeError: Invalid arguments
    at Object.createParameterDeclaration (/usr/lib/node_modules/protoc-gen-ts/node_modules/typescript/lib/typescript.js:170487:19)
    at createParameter (/usr/lib/node_modules/protoc-gen-ts/src/rpc.js:154:23)
    at Object.createGrpcInterfaceType (/usr/lib/node_modules/protoc-gen-ts/src/rpc.js:161:31)
    at Object.<anonymous> (/usr/lib/node_modules/protoc-gen-ts/src/index.js:55:32)
    at Module._compile (node:internal/modules/cjs/loader:1119:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1173:10)
    at Module.load (node:internal/modules/cjs/loader:997:32)
    at Module._load (node:internal/modules/cjs/loader:838:12)
    at Module.require (node:internal/modules/cjs/loader:1021:19)
    at require (node:internal/modules/cjs/helpers:103:18)

Node.js v18.9.0
--ts_out: protoc-gen-ts: Plugin failed with status code 1.
thesayyn commented 2 years ago

Looks like typescript made a breaking change. I'll have look and see what we could use instead without breaking on older version of typescript.

btcSteven commented 2 years ago
image

I solve it ; in your node_modules protoc-gen-ts -> package.json typescript remove ^ use old version

VanIseghemThomas commented 2 years ago

@btcSteven this worked like a charm, thanks! This is clearly an update that should be done to the package.

long1eu commented 1 year ago

Any news on this?

puzzle9 commented 1 year ago

change to "typescript": "4.7.4"

https://github.com/microsoft/TypeScript/issues/50259

long1eu commented 1 year ago

@puzzle9 that also doesn't work. I've forked the repo here and this is what I get

node:internal/modules/cjs/loader:988
  throw err;
  ^

Error: Cannot find module '../src/index'
Require stack:
- /usr/local/lib/node_modules/protoc-gen-ts/bin/protoc-gen-ts.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:985:15)
    at Function.Module._load (node:internal/modules/cjs/loader:833:27)
    at Module.require (node:internal/modules/cjs/loader:1057:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/protoc-gen-ts/bin/protoc-gen-ts.js:2:1)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/usr/local/lib/node_modules/protoc-gen-ts/bin/protoc-gen-ts.js' ]
}
--ts_out: protoc-gen-ts: Plugin failed with status code 1.
puzzle9 commented 1 year ago

@puzzle9 that also doesn't work. I've forked the repo here and this is what I get

node:internal/modules/cjs/loader:988
  throw err;
  ^

Error: Cannot find module '../src/index'
Require stack:
- /usr/local/lib/node_modules/protoc-gen-ts/bin/protoc-gen-ts.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:985:15)
    at Function.Module._load (node:internal/modules/cjs/loader:833:27)
    at Module.require (node:internal/modules/cjs/loader:1057:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/protoc-gen-ts/bin/protoc-gen-ts.js:2:1)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/usr/local/lib/node_modules/protoc-gen-ts/bin/protoc-gen-ts.js' ]
}
--ts_out: protoc-gen-ts: Plugin failed with status code 1.

yea

because it is the source code that needs to be compiled before it can be used

simple you can try

mkdir protoc-gen-ts
cd protoc-gen-ts
yarn add protoc-gen-ts
mv node_modules/protoc-gen-ts ./pgt

cd pgt

change package.json "typescript": "^4.3.4" to "typescript": "4.7.4"

yarn
mv bin/protoc-gen-ts.js bin/protoc-gen-ts

remove global protoc-gen-ts and add path this file

try

Techbinator commented 1 year ago

@puzzle9 that also doesn't work. I've forked the repo here and this is what I get

node:internal/modules/cjs/loader:988
  throw err;
  ^

Error: Cannot find module '../src/index'
Require stack:
- /usr/local/lib/node_modules/protoc-gen-ts/bin/protoc-gen-ts.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:985:15)
    at Function.Module._load (node:internal/modules/cjs/loader:833:27)
    at Module.require (node:internal/modules/cjs/loader:1057:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/protoc-gen-ts/bin/protoc-gen-ts.js:2:1)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/usr/local/lib/node_modules/protoc-gen-ts/bin/protoc-gen-ts.js' ]
}
--ts_out: protoc-gen-ts: Plugin failed with status code 1.

yea

because it is the source code that needs to be compiled before it can be used

simple you can try

mkdir protoc-gen-ts
cd protoc-gen-ts
yarn add protoc-gen-ts
mv node_modules/protoc-gen-ts ./pgt

cd pgt

change package.json "typescript": "^4.3.4" to "typescript": "4.7.4"

yarn
mv bin/protoc-gen-ts.js bin/protoc-gen-ts

remove global protoc-gen-ts and add path this file

try

I did the exact same steps but unfortunately the error persist

dmokel commented 1 year ago

Hi, guys~has this problem been solved?

long1eu commented 1 year ago

Not for me.

On Mon, 21 Nov 2022 at 10:05, David Mokel @.***> wrote:

Hi, guys~has this problem been solved?

— Reply to this email directly, view it on GitHub https://github.com/thesayyn/protoc-gen-ts/issues/170#issuecomment-1321630490, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACG2OVTQBZO3VKZ6PRSJKXTWJMUOFANCNFSM6AAAAAAQAJ35TY . You are receiving this because you commented.Message ID: @.***>

dmokel commented 1 year ago

me too. so bad

dmokel commented 1 year ago

Hi, guys~ I have solved this problem.

you need change package.json "typescript": "^4.3.4" to "typescript": "4.3.4", and remove the node_modules, then npm install or yarn add again.

good luck for you~

long1eu commented 1 year ago

Sorry for being dumb, but package.json of this package? Or the one of my package? Also what if I'm using this package as a global dependency?

dmokel commented 1 year ago

Sorry for being dumb, but package.json of this package? Or the one of my package? Also what if I'm using this package as a global dependency?

the package.json of this package(protoc-gen-ts)

dmokel commented 1 year ago

Sorry for being dumb, but package.json of this package? Or the one of my package? Also what if I'm using this package as a global dependency?

I am using this package as a global dependency too, I change the package (protoc-gen-ts) in my gobal path.

horacimacias commented 1 year ago

I just did a fresh npm install -g protoc-gen-ts and I'm facing the same issue.

I see the issue is now closed; should this now be working without manual fiddling of the protoc-gen-ts's package.json?

thesayyn commented 1 year ago

I just did a fresh npm install -g protoc-gen-ts and I'm facing the same issue.

I see the issue is now closed; should this now be working without manual fiddling of the protoc-gen-ts's package.json?

could you try with npm install -g protoc-gen-ts@next ?

horacimacias commented 1 year ago

thanks. If I use npm install -g protoc-gen-ts@next I get some deprecation warnings but generation succeeds:

DeprecationWarning: 'createPropertyDeclaration' has been deprecated since v4.8.0. Decorators have been combined with modifiers. Callers should switch to an overload that does not accept a 'decorators' parameter.
DeprecationWarning: 'createParameterDeclaration' has been deprecated since v4.8.0. Decorators have been combined with modifiers. Callers should switch to an overload that does not accept a 'decorators' parameter.
DeprecationWarning: 'createConstructorDeclaration' has been deprecated since v4.8.0. Decorators are no longer supported for this function. Callers should switch to an overload that does not accept a 'decorators' parameter.
DeprecationWarning: 'createMethodDeclaration' has been deprecated since v4.8.0. Decorators have been combined with modifiers. Callers should switch to an overload that does not accept a 'decorators' parameter.
DeprecationWarning: 'createClassDeclaration' has been deprecated since v4.8.0. Decorators have been combined with modifiers. Callers should switch to an overload that does not accept a 'decorators' parameter.
DeprecationWarning: 'createImportDeclaration' has been deprecated since v4.8.0. Decorators are no longer supported for this function. Callers should switch to an overload that does not accept a 'decorators' parameter.
DeprecationWarning: 'createModuleDeclaration' has been deprecated since v4.8.0. Decorators are no longer supported for this function. Callers should switch to an overload that does not accept a 'decorators' parameter.
DeprecationWarning: 'createGetAccessorDeclaration' has been deprecated since v4.8.0. Decorators have been combined with modifiers. Callers should switch to an overload that does not accept a 'decorators' parameter.
DeprecationWarning: 'createSetAccessorDeclaration' has been deprecated since v4.8.0. Decorators have been combined with modifiers. Callers should switch to an overload that does not accept a 'decorators' parameter.
DeprecationWarning: 'createIndexSignature' has been deprecated since v4.8.0. Decorators are no longer supported for this function. Callers should switch to an overload that does not accept a 'decorators' parameter.
DeprecationWarning: 'createEnumDeclaration' has been deprecated since v4.8.0. Decorators are no longer supported for this function. Callers should switch to an overload that does not accept a 'decorators' parameter.
DeprecationWarning: 'createTypeParameterDeclaration' has been deprecated since v4.7.0. Use the overload that accepts 'modifiers'
DeprecationWarning: 'createInterfaceDeclaration' has been deprecated since v4.8.0. Decorators are no longer supported for this function. Callers should switch to an overload that does not accept a 'decorators' parameter.

is that expected? anything to worry about?

prodbyola commented 1 year ago

protoc-gen-ts@next

@horacimacias What's your experience? It built with protoc-gen-ts@next but with the same errors as yours. I'm wondering if you didn't encounter any other issue from your end. I'll only be able to test some hours from now.

horacimacias commented 1 year ago

I don't think this is creating any issues for me. I am having other issues but I don't think they are related to this, I still need some time to clarify. If I find this is causing me any problems I'll let you know.