Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: proto is not defined #10

Open
jzfre opened this issue Apr 1, 2022 · 4 comments
Open

ReferenceError: proto is not defined #10

jzfre opened this issue Apr 1, 2022 · 4 comments
Assignees
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers javascript triaged Issue has been triaged

Comments

@jzfre
Copy link

jzfre commented Apr 1, 2022

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

What operating system (Linux, Windows, ...) and version?
Linux Debian 11

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

What did you do?
Steps to reproduce the behavior:

  1. Install protoc through Debian package system
  2. Install google/protobufer
  3. Define two different correct ".proto" files
  4. Import one file to another with "import" statement
  5. Run protoc with "protoc --proto_path=./ --js_out=import_style=commonjs,binary:./ *.proto"
  6. JS code is generated, for file that is importing

var something_pb = require('./something_pb.js'); goog.object.extend(proto, something_pb);

7: Import generated files as javascript code:
require("./proto/hello_pb")

  1. Run the code

What did you expect to see

Everything goes fine

What did you see instead?

goog.object.extend(proto, core_pb); ^ ReferenceError: proto is not defined

@ShogoSaito0607
Copy link

ShogoSaito0607 commented May 11, 2022

@xrep
I face this same issue.
As temporary escape for this, I merged three proto files to one file...
Of course, I'm very aware this solution is not better essentially :(

Versions
Protocol Buffers v3.19.4
node: v14.15.1

@acozzette acozzette transferred this issue from protocolbuffers/protobuf May 16, 2022
@dibenede
Copy link
Contributor

We don't use commonjs often, so it's unclear what the issue is. We'll need to dig into this a bit to see what's going wrong.

@dibenede dibenede assigned dibenede and unassigned lukesandberg Aug 26, 2022
@dibenede dibenede added documentation Improvements or additions to documentation good first issue Good for newcomers triaged Issue has been triaged labels Aug 26, 2022
@dibenede
Copy link
Contributor

I'm having trouble reproducing this, so wondering if it's a subtlety of how your projects are structured. My test environment looks like:

project/
- protos/
-- foo.proto
-- foo_pb.js
-- bar.proto
-- bar_pb.js

- tests/
- - test.js

which was generated by running: protoc --plugin=../bin/protoc-gen-js --proto_path=./protos/ --js_out=import_style=commonjs,binary:./protos/ protos/*.proto from under project/

My tests/test.js has the following requires:

const foopb = require('../protos/foo_pb');
const barpb = require('../protos/bar_pb');

@jzfre @ShogoSaito0607 could either of you describe a project layout that's causing trouble for you?

yaobinwen added a commit to yaobinwen/protobuf-javascript-issue-10 that referenced this issue Dec 6, 2022
yaobinwen added a commit to yaobinwen/protobuf-javascript-issue-10 that referenced this issue Dec 6, 2022
yaobinwen added a commit to yaobinwen/protobuf-javascript-issue-10 that referenced this issue Dec 6, 2022
@yaobinwen
Copy link

I'm wondering if OP got the error in a React.js app or something else. Today I ran into the same error in my React.js app and I created this repo to reproduce it. @dibenede I'm wondering if this can help you figure out something. See my README for more details (including some other existing work that provides a few workarounds).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers javascript triaged Issue has been triaged
Projects
None yet
Development

No branches or pull requests

6 participants