-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Uncaught TypeError: Cannot read property 'emptyArray' of undefined #1503
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
Comments
I do have the same error on my project. It's quite a big project so I don't think it would be super helpful to use it as a repro - it's open source code but too big to help. |
@ZiyunHe could you share your repro if it's smaller or give instructions to reproduce your config ? Thanks On my side the issue is new ~1 week so I have not yet a clear issue of where it comes from (I have no direct dep on protobufjs). |
@vicb I actually figured out because I was using snowpack. rollup/rollup#2747 check out this issue for more information. Are you using snowpack as well? I had to switch to webpack because of the need of protobufjs library |
I just figure out the circular dependency problem by checking the generated code:
You would expect to see the dependency logged before types_1 but it is not the case... I do use rollup, your link will help, thanks ! |
@ZiyunHe I am trying to create a simple repro to submit a bug to submit a bug to the repo of @rollup/plugin-commonjs. Any chance you have a repro available somewhere that I could use as a starting point for a REPL ? Thanks |
@vicb |
Thanks @ZiyunHe. Please you please cc when you create that issue. It will probably help me reproduce with rollup too. |
Same here. Any update @ZiyunHe ? |
I commented on the issue of @ZiyunHe in the snowpack. It might be a module resolution problem due to the same name between a file and a directory. |
Temporary bypass for rollup users:
then the reason in circular dependencies, but even https://github.com/rollup/plugins/tree/feat/commonjs-circular-dependencies/packages/commonjs won't fix this issue (I have compiled code on local env and replace in node_modules folder - no luck). The main solution for now, just to create static module. |
@logvik maybe you should comment on rollup/plugins#658 if you have an easy repro you can share with @lukastaegert @choyongjoon the problem with rollup is not cause by the file |
@vicb rollup is not the reason of circular dependencies. That's why I have publish my bypass way here. Many people will read and use. Also, I think that need to change this package, because it is not ok to have circular dependencies at any case.
|
Agreed.
Here I don't agree. // main.js
const dep = require('./dep.js');
exports.foo = 'foo';
console.log(dep.getMain().foo);
// dep.js
const main = require('./main.js');
exports.getMain = () => main;
Your workaround works because your app (or lib) is the direct consumer of the proto. |
Anyone still looking at this? I have a project I trying to migrate to Vite. managed to get everything working except production build. It seems rollup/plugins#658 is not the only fix required. According to the disclaimer in rollup/plugins#658 (comment)
|
Is there any workaround for rollup to handle protobufjs in production build? Maybe a way to skip optimization of specific modules/files? |
A note from my case - when using
instead of
I managed to get it working with |
I can confirm that @kskalski's solution fixed it for me too! Using vite (probably an esbuild issue) |
We are finalizing a new version of the commonjs plugin in rollup/plugins#1038. It is pre-published as @rollup/plugin-commonjs@beta. Please give it a spin to see if it resolves the issue, ideally without additional config needed. |
protobuf.js version: 6.10.1
Im using typescript and trying with awesomemessage example. It reports error of emptyArray.
import protobuf from 'protobufjs';
protobuf.load("t.proto", function(err, root) {
...
})
Anyone has idea? Thanks
The text was updated successfully, but these errors were encountered: