Skip to content

Support for ES Modules (import/export) in protoc --js_out #248

@Vuhag123

Description

@Vuhag123

Today, protoc --js_out generates JavaScript using CommonJS (require) or Closure-style imports. This works with Node.js and bundlers, but it does not produce native ES Modules (import/export) that browsers and modern toolchains expect.

Problem:

Generated *_pb.js files cannot be used directly as ES modules in browsers.

Projects like gRPC-Web are adding TypeScript and ESM-friendly stubs, but they cannot fully adopt ESM until the protobuf message code supports it.

Users must currently rely on bundlers (Webpack, Rollup, Vite, Closure Compiler, etc.) to convert CommonJS to ESM.

Request:

Add an option to --js_out to generate native ESM output (import/export), similar to how --import_style=commonjs or --import_style=typescript work today.

This would enable a full ESM workflow:

import { HelloRequest } from "./foo_pb.js";
import { FooClient } from "./foo_grpc_web_pb.js";

This aligns with the wider JavaScript ecosystem migration toward ESM as the standard module system.

Impact:

Allows protobuf users to consume generated code directly in browsers without bundlers.

Unlocks full ESM compatibility for downstream projects like gRPC-Web.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions