protobuf.js version: v6.8.8 (but I can see the issue being present in latest master at time of writing)
The issue experienced here is a bit tricky, but due to circular dependencies in the code, it makes it impossible to package this dependency using EG. rollup, as stated here and with a repository to reproduce it here. This incidentally (?) works when consuming it normally via node, due to how they handle circular references.
I would really appriciate it if this would be considered a bug.
Using madge, it's easy to detect circular dependencies in the code.
$ git clone [email protected]:protobufjs/protobuf.js.git
$ cd protobuf.js/
$ npx madge --circular src/index.js
Processed 33 files (769ms)
✖ Found 28 circular dependencies!
1) enum.js > namespace.js > field.js
2) enum.js > namespace.js > field.js > object.js > util.js
3) enum.js > namespace.js > field.js > object.js > util.js > root.js
4) field.js > object.js > util.js > root.js
5) namespace.js > field.js > object.js > util.js > root.js
6) field.js > object.js > util.js > root.js > oneof.js
7) object.js > util.js > root.js > oneof.js
8) util.js > root.js > oneof.js
9) util.js > root.js
10) converter.js > enum.js > namespace.js > field.js > object.js > util.js > type.js
11) enum.js > namespace.js > field.js > object.js > util.js > type.js > decoder.js
12) util.js > type.js > decoder.js > types.js
13) util.js > type.js > decoder.js
14) enum.js > namespace.js > field.js > object.js > util.js > type.js > encoder.js
15) util.js > type.js > encoder.js
16) enum.js > namespace.js > field.js > object.js > util.js > type.js
17) field.js > object.js > util.js > type.js
18) field.js > object.js > util.js > type.js > mapfield.js
19) util.js > type.js > mapfield.js
20) util/minimal.js > util/longbits.js
21) namespace.js > field.js > object.js > util.js > type.js
22) object.js > util.js > type.js > service.js > method.js
23) util.js > type.js > service.js > method.js
24) namespace.js > field.js > object.js > util.js > type.js > service.js
25) util.js > type.js > service.js
26) util.js > type.js
27) enum.js > namespace.js > field.js > object.js > util.js > type.js > verifier.js
28) util.js > type.js > verifier.js
+1 the same issue
+1 too
👋 same here
(!) Circular dependencies
../node_modules/protobufjs/src/util/minimal.js -> ../node_modules/protobufjs/src/util/longbits.js -> ../node_modules/protobufjs/src/util/minimal.js
../node_modules/protobufjs/src/util/minimal.js -> ../node_modules/protobufjs/src/util/longbits.js -> /home/hasparus/my-project/node_modules/protobufjs/src/util/minimal.js?commonjs-proxy -> ../node_modules/protobufjs/src/util/minimal.js
After I update my rollup to v2.23.0 and using @rollup/plugin-commonjs, my issue is fixed.
The most important is that I set the transformMixedEsModules to true.
commonjs({ transformMixedEsModules: true, })
@HAHAHA44 I have followed what you have mentioned but I am still having the same issue.
Would you mind sending me your rollup config?
same issue here also :/
i have same issue, do you save ?
same issue, protobufjs version 6.10.2, I use rollup to bundle the project. anyone solved it ?
Same issue. Any plan to fix this?
Same issue. Now I have to use webpack.
Plot twist: https://github.com/rollup/plugins/pull/658
This PR finally adds general support for circular dependencies to the commonjs plugin.
https://github.com/rollup/plugins/pull/658 did not fully fix this. See disclaimer in: https://github.com/rollup/plugins/pull/658#issue-526192287.
While this PR adds support for circular references, it does not add support for exact execution order for inline require statements. As some packages with circular references also rely on that, they may still not work. But often, they can now be made to work by manually tweaking the execution order via strategic imports
Most helpful comment
👋 same here