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

Import from react-datepicker duplicates date-fns modules #2769

Open
alexandrchebotar opened this issue Feb 28, 2021 · 8 comments
Open

Import from react-datepicker duplicates date-fns modules #2769

alexandrchebotar opened this issue Feb 28, 2021 · 8 comments

Comments

@alexandrchebotar
Copy link

Describe the bug
Because of direct import from date-fns/[module] when you import react-datepicker with es6 import you add that modules to bundle.
Same time if you import something from date-fns or other library that uses date-fns, for example date-fns-tz, you add to bundle modules from date-fns/esm. As a result you duplicate some date-fns modules.

To Reproduce
Steps to reproduce the behavior:

  1. Import react-datepicker:
import DatePicker from "react-datepicker";
  1. Import something from date-fns:
import { parseISO } from "date-fns";
import { format, utcToZonedTime } from 'date-fns-tz';
  1. Make build.
  2. See duplicated modules in bundle.

Expected behavior
import DatePicker from "react-datepicker" should add modules from date-fns/esm/

Screenshots
image

Additional context
React Date Picker version - 3.6.0.

@tu4mo

This comment has been minimized.

@alexandrchebotar
Copy link
Author

@tu4mo these are different issues.

@tu4mo
Copy link
Contributor

tu4mo commented Mar 6, 2021

@alexandrchebotar Oh, sorry. Was looking at the wrong thing.

@himynameistimli
Copy link

@alexandrchebotar have you found a temporary workaround to force the use of a common date-fns module?

@magiskboy
Copy link

I hope that this issue will be resolved in near future

@magiskboy
Copy link

magiskboy commented Feb 22, 2022

I think rc-picker uses star import for all locales of date-fns so this leads to growing bundle size
https://github.com/react-component/picker/blob/master/src/generate/dateFns.ts#L26

@gabycperezdias
Copy link

Any updates on this?

@ThenTech
Copy link

Looking through date-fns/date-fns#2207 and verifying that treeshaking should work in my project, I think the "duplication" mentioned here is just because react-datepicker actually does import all those date-fns functions? Or am I missing something else?

Refer to the date_utils.js file where 57 functions are imported, used and re-exported in some way to be used elsewhere.

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

6 participants