Skip to content

ECMAScript support missing? #2047

@luisasc

Description

@luisasc

Hi, I think protobufjs is missing ECMAScript support. I'm using protobufjs v7.4.0 and protobufjs-cli v1.1.3 in an Angular 19 project (newly migrated from v18), and getting this warning in my console now:

▲ [WARNING] Module 'protobufjs/minimal' used by 'src/types/protobuf/automotive-testing.js' is not ESM
CommonJS or AMD dependencies can cause optimization bailouts.
For more information see: https://angular.dev/tools/cli/build#configuring-commonjs-dependencies

Following the link, I can see how to workaround this issue with Angular by making an exception for a specific dependency to still use CommonJS, but ideally I would like to change the pbjs and pbts commands to generate the .ts and .d.ts files to use ESM modules.

I've tried out these different commands, but each one resulted in the build warning from Angular:

  • pbjs --es6 --target static-module --wrap es6 --dependency protobufjs/minimal.js --out src/types/protobuf/test.js protobuf/Test.proto && pbts --out src/types/protobuf/test.d.ts src/types/protobuf/test.js
  • pbjs --dependency protobufjs/minimal.js --target static-module --wrap commonjs --out src/types/protobuf/test.js protobuf/Test.proto
  • pbts --main --out src/types/protobuf/test.d.ts src/types/protobuf/test.js && node src/types/protobuf/tools/wrap-pbts-result.js

The tools/wrap-pbts.result was suggested here in this example project

As far as I understood the documentation, the command option --wrap es6 (or --es6) should enable ES6, which should also include usage of ESM module imports and exports. However this does not work as expected. Should I have used a different command or is the error within the protobufjs or protobufjs-cli library?

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions