connectrpc / connect-es

The TypeScript implementation of Connect: Protobuf RPC that works.

Home Page:https://connectrpc.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

js_import_style=commonjs still generates 'export const MyService' instead of `exports.MyService`

pmunin opened this issue · comments

Describe the bug

In buf.gen.yaml i specify to use commonjs style:

version: v1
plugins:
  - name: connect-es
    out: ./dist
    opt:
    - target=js+dts
    - js_import_style=legacy_commonjs    

But it still generates js that exports in ES6 style even though it uses require to import modules. Eventually when I use that generated code in Nodejs it fails with error:

MyService.v2_connect.js:17
export const MyService = {
^^^^^^

SyntaxError: Unexpected token 'export'

The generated file looks like this:

// @generated by protoc-gen-connect-es v0.13.0 with parameter "target=js+dts,js_import_style=legacy_commonjs"
// @generated from file myService.v2.proto (package v2, syntax proto3)
/* eslint-disable */
// @ts-nocheck

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

const { MyMethodRequest, MyMethodResponse } = require("./myService.v2_pb.js");
const { MethodKind } = require("@bufbuild/protobuf");

/**
 * MyService definition.
 *
 * @generated from service v2.MyService
 */
export const MyService = {
  typeName: "v2.MyService",
  methods: {
    /**
     * @generated from rpc v2.MyService.myMethod
     */
    myMethod: {
      //...
    }
  }
};

To Reproduce

The bug is not specific to the RPC payload. See the error above.

Environment (please complete the following information):

  • @connectrpc/connect: 1.4.0
  • @connectrpc/protoc-gen-connect-es: ^1.4.0
  • Node.js version: 18.12.1

Apparently had some old dependencies installed