Tintef/react-google-places-autocomplete

Dependencies are bundled in the build output

bstefanescu opened this issue · 8 comments

All the dependencies (not the peer dependencies) are bundled in the build output files.
The build is thus including @googlemaps/js-api-loader as well as react-select with all of its own dependencies (like @emotion/react). Apart the big size of the output file, this may cause problems at runtime.

In my product I am using libraries like react-select chakra-ui etc. that depends on @emotion/react. Because react-google-places-autocomplete is embeding the react-select library (and thus, @emotion/react) I have this warning in the browser:

index.es.js?dc37:23 You are loading @emotion/react when it is already loaded. 
Running multiple instances may cause problems. 
This can happen if multiple versions are used, or if multiple builds of the same version are used.

Fix: the build output must not embed dependencies. Dependencies must be declared as external in rollup config file.

Please verify if the changes on the branch issue/280 fix that warning for you (see here how to build locally and link to your project).

The output file is not affected too much by that change as far as I can see:

* Before externals
Created bundle index.es.js: 140.41 kB → 44.99 kB (gzip)
Created bundle index.js: 141.26 kB → 45.11 kB (gzip)

* After externals
Created bundle index.js: 136.59 kB → 43.54 kB (gzip)
Created bundle index.es.js: 135.84 kB → 43.44 kB (gzip)

An addition could be to set react-select as a peerDependecy as well. This should solve your problem (but each user would have to install react-select on their own) and it does decrease the build size significantly:

Created bundle index.js: 5.19 kB → 2.08 kB (gzip)
Created bundle index.es.js: 5.85 kB → 2.48 kB (gzip)

You can also test this approach on issue/280-alternative

I'm seeing the same issue - I'll try building this branch today and confirm the fix

@bstefanescu or @steveariss did any of you had an opportunity to review this?

Any update on this fix?

I'm still waiting on feedback from either @bstefanescu or @steveariss.

If you @zedrdave can review the branches and lmk if the problem still exists would be great.

Unfortunately won't be able to review this myself in the coming few days. Will see if someone on our team can give it a try…

Was this ever fixed?