protocolbuffers / protocolbuffers/protobuf-javascript

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

Open
#8 9 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

javascript question
Dominant language
JavaScript
Stars
471
Forks
91
Avg merge
3h 57m
Merged PRs (30d)
2

Description

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);

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the shown protoc command and Node.js v16.13.0, then inspect the generated *_pb.js code around the global initialization at line 16. Compare behavior with protobuf versions 3.19.1–3.19.4; done means the generated CommonJS files can be imported and used in Node.js without a window error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.