Open tkafka opened 1 year ago
Providing a custom fixed dependency name and wrapper according to this post works, but ES6 module generation should work out of the box.
protobuf
only exports minimal
as commonjs. It would be neat to publish a module version as well.
See here: https://www.typescriptlang.org/docs/handbook/esm-node.html https://nodejs.org/api/packages.html#conditional-exports
It works.
Replace $protobuf
with $protobuf.default
/*eslint-disable block-scoped-var, id-length, no-control-regex, no-magic-numbers, no-prototype-builtins, no-redeclare, no-shadow, no-var, sort-vars*/
import * as $protobuf from "protobufjs/minimal.js";
// Common aliases
const $Reader = $protobuf.default.Reader, $Writer = $protobuf.default.Writer, $util = $protobuf.default.util;
// Exported root namespace
const $root = $protobuf.default.roots["default"] || ($protobuf.default.roots["default"] = {});
......
I'm also affected by this bug, and I concur that the es6 generation is just actually broken because this:
import * as $protobuf from "protobufjs/minimal"
Is not a valid es6 import given the project structure. Adding .js for me cascades into other issues, but I was able to substitute:
import $protobuf from "protobufjs";
though I haven't tested everything yet.
protobuf.js version: 7.2.5
Repro steps:
Expected behavior: The generated code build and runs.
Actual behavior: Running the code results in error:
I need to replace
for
... in order to make the generated module runnable.
Possible related: https://github.com/protobufjs/protobuf.js/issues/1862