You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After breaking my head for 2 days on this issue, today I used patch-package to patch date-fns-tz@1.3.7 for the project I'm working on.
I replaced the CJS imports with ESM imports under the date-fns-tz/esm directory.
Here is the diff that solved my problem:
diff --git a/node_modules/date-fns-tz/esm/format/index.js b/node_modules/date-fns-tz/esm/format/index.js
index 440e5a9..e1b6a3c 100644
--- a/node_modules/date-fns-tz/esm/format/index.js+++ b/node_modules/date-fns-tz/esm/format/index.js@@ -1,4 +1,4 @@-import dateFnsFormat from 'date-fns/format/index.js'+import dateFnsFormat from 'date-fns/esm/format/index.js'
import formatters from './formatters/index.js'
import toDate from '../toDate/index.js'
diff --git a/node_modules/date-fns-tz/esm/formatInTimeZone/index.js b/node_modules/date-fns-tz/esm/formatInTimeZone/index.js
index bbb2c4e..6763dc1 100644
--- a/node_modules/date-fns-tz/esm/formatInTimeZone/index.js+++ b/node_modules/date-fns-tz/esm/formatInTimeZone/index.js@@ -1,4 +1,4 @@-import cloneObject from 'date-fns/_lib/cloneObject/index.js'+import cloneObject from 'date-fns/esm/_lib/cloneObject/index.js'
import format from '../format/index.js'
import utcToZonedTime from '../utcToZonedTime/index.js'
diff --git a/node_modules/date-fns-tz/esm/toDate/index.js b/node_modules/date-fns-tz/esm/toDate/index.js
index 6acea0e..d4340cc 100644
--- a/node_modules/date-fns-tz/esm/toDate/index.js+++ b/node_modules/date-fns-tz/esm/toDate/index.js@@ -1,5 +1,5 @@-import toInteger from 'date-fns/_lib/toInteger/index.js'-import getTimezoneOffsetInMilliseconds from 'date-fns/_lib/getTimezoneOffsetInMilliseconds/index.js'+import toInteger from 'date-fns/esm/_lib/toInteger/index.js'+import getTimezoneOffsetInMilliseconds from 'date-fns/esm/_lib/getTimezoneOffsetInMilliseconds/index.js'
import tzParseTimezone from '../_lib/tzParseTimezone/index.js'
import tzPattern from '../_lib/tzPattern/index.js'
diff --git a/node_modules/date-fns-tz/esm/zonedTimeToUtc/index.js b/node_modules/date-fns-tz/esm/zonedTimeToUtc/index.js
index 4451b67..4ad4f50 100644
--- a/node_modules/date-fns-tz/esm/zonedTimeToUtc/index.js+++ b/node_modules/date-fns-tz/esm/zonedTimeToUtc/index.js@@ -1,4 +1,4 @@-import cloneObject from 'date-fns/_lib/cloneObject/index.js'+import cloneObject from 'date-fns/esm/_lib/cloneObject/index.js'
import toDate from '../toDate/index.js'
import tzPattern from '../_lib/tzPattern/index.js'
import tzParseTimezone from '../_lib/tzParseTimezone/index.js'
Hi! 馃憢
Firstly, thanks for your work on this project! 馃檪
I was facing an issue on my UI library that uses
date-fns-tz/esm/*
.My library setup uses
vite
withpreserveModules
option set totrue
.The bundling was successful but during runtime the CJS libs that are imported within were throwing error.
Related:
After breaking my head for 2 days on this issue, today I used patch-package to patch
date-fns-tz@1.3.7
for the project I'm working on.I replaced the CJS imports with ESM imports under the
date-fns-tz/esm
directory.Here is the diff that solved my problem:
This issue body was partially generated by patch-package.
Hope this workaround helps others.
The text was updated successfully, but these errors were encountered: