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

Commonjs pb exports do not carry intellisense #18

Open
madaster97 opened this issue Mar 6, 2021 · 4 comments
Open

Commonjs pb exports do not carry intellisense #18

madaster97 opened this issue Mar 6, 2021 · 4 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers javascript triaged Issue has been triaged

Comments

@madaster97
Copy link

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

What operating system (Linux, Windows, ...) and version?
Ubuntu 20.04, x86_64

What runtime / compiler are you using (e.g., python version or gcc version)
protoc pre-built compiler

What did you do?
Steps to reproduce the behavior:

  1. Create a sample protoc file, here simple.proto. I took it from this example, modified to "proto3"
  2. Use the compiler to autogen JavaScript code: protoc --js_out=import_style=commonjs,binary:. simple.proto
  3. Use the default export as an object with expected Schema: const Schema = require('./simple_pb');
  4. Attempt to use the expected Class(es) on that object: const test = new Schema.Test1();
  5. See that you do not receive intellisense for the Test1() class, nor for expected operations it's instances

What did you expect to see
Intellisense for the simple_pb operations on the default export.

What did you see instead?
No Intellisense, but the operations themselves do execute (setting values, serialzing to Binary).

I was able to "fix" the issue by changing the last line of the simple_pb.js file. The goog export extension did not work, so I just commented it out and spread the goog and proto objects into module.exports:

module.exports = {...goog, ...proto};
// goog.object.extend(exports, proto);
@thesayyn
Copy link

it is because it uses google module system instead of commonjs or esm and not likely to be fixed soon.

@piekstra
Copy link

piekstra commented Jun 7, 2021

I am running into this issue and it is very frustrating

@elharo elharo added javascript enhancement New feature or request labels Aug 26, 2021
@thesayyn
Copy link

@acozzette acozzette transferred this issue from protocolbuffers/protobuf May 16, 2022
@dibenede dibenede added the triaged Issue has been triaged label Sep 2, 2022
@dibenede
Copy link
Contributor

dibenede commented Sep 2, 2022

It sounds like the issue is the way we manage exports in the code generator. We need to do a more typical assignment to exports here:

printer->Print("goog.object.extend(exports, $package$);\n", "package",

it might work to simply delete that code and change GetNamespace to return "exports" in common js mode.

@dibenede dibenede added the good first issue Good for newcomers label Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers javascript triaged Issue has been triaged
Projects
None yet
Development

No branches or pull requests

6 participants