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

What is the "Could not redupe module ..." actually mean? #36

Open
ceremcem opened this issue Aug 5, 2020 · 3 comments
Open

What is the "Could not redupe module ..." actually mean? #36

ceremcem opened this issue Aug 5, 2020 · 3 comments

Comments

@ceremcem
Copy link

ceremcem commented Aug 5, 2020

I received an error:

browserify : Could not redupe module /path/to/scada.js/node_modules/moment/moment.js

What does it mean? What should I do?

@goto-bus-stop
Copy link
Member

Browserify internally dedupes modules: if there are two identical files in the build, it will replace one of them with a stub that references the other. For tree shaking, this causes an issue, because the stub file does not appear to have any exports just by looking at the source. common-shakeify works around it by temporarily un-deduping the module, that is by replacing the stub with the original source.

This "reduping" can fail if browserify has deduped a module, but the original source cannot be retrieved.

Looking at the code I can see a potential cause of this … common-shakeify expects the original source to be earlier in browserify's build pipeline than the deduped stub module. If some plugin sorted the pipeline before common-shakeify gets to it, it's possible that the order is reversed.

I think the only feasible way to work around it is by checking if you have multiple copies of moment in your dependency tree. You can try to use npm dedupe to hopefully reduce it to one. Then browserify does not need to do the deduping at all. Also, you can run browserify with the --no-dedupe flag, though this may cause bundle sizes to increase quite a bit.

@ceremcem
Copy link
Author

Thanks. Now I understand more what browserify does under the hood.

I think the only feasible way to work around it is by checking if you have multiple copies of moment in your dependency tree.

Yes, I know there is. I can remove it by editing my code (it also might be a code cleanup) but I feel like it shouldn't be the way to go. I'll try this option anyway.

This "reduping" can fail if browserify has deduped a module, but the original source cannot be retrieved.

I can't imagine how this step fails. I might take a look at this process. It might be interesting to find out this actual cause.

@goto-bus-stop
Copy link
Member

I can remove it by editing my code (..) but I feel like it shouldn't be the way to go.

I agree. I basically thought it couldn't fail, which is why I didn't put much effort into the error message 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants