Skip to content

Timezone support broken in Vite due to dynamic require of date-fns-tz #6204

Description

@PurkkaKoodari

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:

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.
Image

To Reproduce
Steps to reproduce the behavior:

  1. See the minimal Vite setup in https://codesandbox.io/p/devbox/fmvlts (use https://fmvlts-5173.csb.app/ to view outside the editor)
  2. Observe times are rendered in local time
  3. Observe the timeZone prop requires "date-fns-tz" package warning 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions