Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭
#248 1 条评论 13 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
30/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
javascript
领域
tooling

调研方向

首先跟踪 protoc --js_out 如何处理现有的 --import_style=commonjs 和 --import_style=typescript 选项,然后检查生成的 *_pb.js 输出路径。完成标准是新增一个选项,生成可直接在浏览器中运行的原生 ESM import/export 输出,并覆盖生成模块的行为。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
JavaScript
星标
471
派生
91
平均合并
3 小时 57 分钟
30 天内合并 PR
2

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

protocolbuffers/protobuf-javascript 的其他 Issue

查看 protocolbuffers/protobuf-javascript 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。