3 ms·
Can someone clarify what would happen in this scenario: - My app requires React. - My app also requires FooBarComponent whose dist is just a giant index.js wh
by joeframbach 11y ago
Can someone clarify what would happen in this scenario:
- My app requires React.
- My app also requires FooBarComponent whose dist is just a giant index.js which includes its own copy of React.
- Now I get a bunch of errors because FooBarComponent and MyApp can't share anything between themselves. React really doesn't like it when two copies are running.
- exogen 11y agoFooBarComponent shouldn't have been packaged that way (it can include such a dist file for some people to use, but the npm package shouldn't export that). The typical way is for it to not include React as a `dependency` at all but a `peerDependency`. Then everything will be importing the same instance.
- joeframbach 11y ago> (it can include such a dist file for some people to use, but the npm package shouldn't export that) I think that is exactly what the article is suggesting we do.
- lollipop25 11y agoThe root of the problem is why FooBarComponent is a giant index.js. Also, why does it have React bundled if it expects to be a reusable component? Also, frameworks like React etc. shouldn't be a bundled dependency. They should be an external dependency or a top-level dependency.