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

Error when calling tsc together with the outputIndex=true option #1126

Open
skycrazyk opened this issue Oct 22, 2024 · 1 comment
Open

Error when calling tsc together with the outputIndex=true option #1126

skycrazyk opened this issue Oct 22, 2024 · 1 comment

Comments

@skycrazyk
Copy link

skycrazyk commented Oct 22, 2024

Error when calling tsc together with the outputIndex=true option in version 2.2.4. Everything normal in version 1.181.2

Error

General view of errors

error TS4023: Exported variable 'X' has or is using name 'MessageFns' from external module "/path/to/dist/google/protobuf/empty" but cannot be named

Error example

dist/clients/clients.ts:1045:14 - error TS4023: Exported variable 'ClientsDefinition' has or is using name 'MessageFns' from external module "/path/to/dist/google/protobuf/empty" but cannot be named.

Protoc CLI command

protoc -I=path/to/proto \
	--plugin=path/to/node_modules/.bin/protoc-gen-ts_proto \
 	--ts_proto_opt=env=browser,outputServices=generic-definitions,outputJsonMethods=false,esModuleInterop=true,useOptionals=messages,exportCommonSymbols=false,useDate=false,useExactTypes=false,outputIndex=true \
 	--ts_proto_out=path/to/dist \ 
        path/to/proto/**/*

Typescript CLI command

tsc --declaration --declarationMap --sourceMap --rootDir ./dist

Dependencies

Global

protoc --version
libprotoc 28.2

NPM

{
    "@bufbuild/protobuf": "^2.2.0",
    "ts-proto": "2.2.4",
    "typescript": "5.6.3"
}

Protofile example

syntax = "proto3";

import "google/protobuf/empty.proto";

option go_package = "git.company.com/project/go/proto/clients;clients";

package content.clients;

message Client {
  message OAuth {
      string client_id = 4;     
      string auth_id = 5;   
      string token_url = 10;     
      string client_secret = 11;   
  }

  message APIKey {
    string key = 1;
    bool rotate = 2;
  }

  message TLS {
    string subject = 1;
  }

  string id = 1;
  string space_id = 2;
  string name = 3;
  string description = 6;
  optional bool disabled = 7;
  string role_id = 8;
  OAuth oauth = 10;
  TLS tls = 11;
  APIKey api_key = 12;
}

message CreateRequest {
  Client client = 1;
}

message CreateResponse {
  Client created = 1;
}

message GetRequest {
  string space_id = 1;
  string id = 2;
}

message GetResponse {
  Client client = 1;
}

message GetByRequest {
  string space_id = 1;
  string oauth_client_id = 2;
  string tls_subject= 3;
  string api_key = 4;
}

message GetByResponse {
  Client client = 1;
}

message UpdateRequest {
  Client client = 1;
}

message ListRequest {
  string space_id = 1;
}

message ListResponse {
  repeated Client clients = 1;
}

message DeleteRequest {
  string space_id = 1;
  string id = 2;
}

message EnableRequest {
  string space_id = 1;
  string id = 2;
  bool enable = 3;
}

service Clients  {
  rpc Create(CreateRequest) returns(CreateResponse) {}
  rpc Get(GetRequest) returns(GetResponse) {}
  rpc GetBy(GetByRequest) returns(GetByResponse) {}
  rpc Update(UpdateRequest) returns(google.protobuf.Empty) {}
  rpc List(ListRequest) returns(ListResponse) {}
  rpc Delete(DeleteRequest) returns(google.protobuf.Empty) {}
  rpc Enable(EnableRequest) returns(google.protobuf.Empty) {}
}
@skycrazyk skycrazyk changed the title Error when calling tsc together with the outputIndex=true option Error when calling tsc together with the outputIndex=true option Oct 22, 2024
@skycrazyk skycrazyk changed the title Error when calling tsc together with the outputIndex=true option Error when calling tsc together with the outputIndex=true option Oct 22, 2024
@stephenh
Copy link
Owner

Hi @skycrazyk ; I'm not sure what the issue is here; this github comment:

microsoft/TypeScript#5711 (comment)

Insinuates that adding an import of MessageFns to clients.ts will fix things.

Can you try adding that import and see if that fixes it?

It also seems like the error is related to the --declaration flag, so maybe we should try running that on for our integration/* test suite and see what happens? 🤔

If you could try that, i.e. make sure our integration test suite is using the declaration flag, and see what happens in a PR build, that would be great. Thanks!

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

2 participants