-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
Describe the bug
When developing with Vite with the default React config, the new timeZone prop fails to work.
This seems to be due to the code dynamically using require to import date-fns-tz, which apparently isn't supported by Vite:
react-datepicker/src/date_utils.ts
Lines 118 to 120 in 644f2f5
| const dateFnsTzModuleName = "date-fns-tz"; | |
| // eslint-disable-next-line @typescript-eslint/no-require-imports | |
| dateFnsTz = require(dateFnsTzModuleName) as DateFnsTz; |
Screenshot from debugger, inside the require call in the above code.

To Reproduce
Steps to reproduce the behavior:
- See the minimal Vite setup in https://codesandbox.io/p/devbox/fmvlts (use https://fmvlts-5173.csb.app/ to view outside the editor)
- Observe times are rendered in local time
- Observe the
timeZone prop requires "date-fns-tz" packagewarning in console
Expected behavior
Dates rendered in configured timeZone (Pacific/Auckland in example to make it clear).
If this requires specific configuration on the Vite side, it would be a good idea to document in timezone.md (but I couldn't find anything to enable dynamic require in Vite).
Screenshots
N/A
Desktop (please complete the following information):
- OS: Debian testing
- Browser: Firefox 147.0b9