react-google-places-autocomplete icon indicating copy to clipboard operation
react-google-places-autocomplete copied to clipboard

Dependencies are bundled in the build output

Open bstefanescu opened this issue 3 years ago • 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.

bstefanescu avatar Jul 16 '22 09:07 bstefanescu

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

Tintef avatar Jul 16 '22 17:07 Tintef

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

steveariss avatar Aug 12 '22 13:08 steveariss

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

Tintef avatar Oct 12 '22 01:10 Tintef

Any update on this fix?

zedrdave avatar Nov 13 '22 22:11 zedrdave

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.

Tintef avatar Nov 14 '22 11:11 Tintef

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…

zedrdave avatar Nov 15 '22 11:11 zedrdave

Was this ever fixed?

melloware avatar Oct 29 '23 14:10 melloware