js_import_style=commonjs still generates 'export const MyService' instead of `exports.MyService`
pmunin opened this issue · comments
Philipp Munin commented
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
Philipp Munin commented
Apparently had some old dependencies installed