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

The generated commonjs `*_pb.js` files don't work in Node.js environment

未关闭
#8 9 条评论 7 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
领域
backend

调研方向

使用所示的 protoc 命令和 Node.js v16.13.0 重现该问题,然后检查第 16 行全局初始化附近生成的 *_pb.js 代码。比较 protobuf 3.19.1–3.19.4 版本的行为;当生成的 CommonJS 文件可以在 Node.js 中导入和使用且不会出现 window 错误时,即表示完成。

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

描述

javascript question

This bug is a rebirth of protocolbuffers/protobuf#9152, which has already been fixed in v3.19.1. It seems the fix hasn't been delivered to the latest version.

What version of protobuf and what language are you using?
Version: v3.20.1
Language: Javascript

What operating system (Linux, Windows, ...) and version?
macOs Monterey v12.3.1

What runtime / compiler are you using (e.g., python version or gcc version)
Node.js v16.13.0

What did you do?

  1. Run protoc --js_out=import_style=commonjs,binary:path/to/out/dir --proto_path=. *.proto
  2. Try to import and use the generated *_pb.js files.

What did you expect to see
Import and use without errors (just as in 3.19.1 - 3.19.4).

What did you see instead?

ReferenceError: window is not defined

   14 | var jspb = require('google-protobuf');
   15 | var goog = jspb;
 > 16 | var global = (function() { return this || window || global || self || Function('return this')(); }).call(null);
主要语言
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 摘要。