marnusw / date-fns-tz

Complementary library for date-fns v2 adding IANA time zone support
MIT License
1.06k stars 116 forks source link

Support for date-fns v3 #260

Closed woothu closed 6 months ago

woothu commented 9 months ago

Date-fns just released a stable version 3: image

Is this package going to support the new version?

marnusw commented 9 months ago

Hey @woothu, I haven't had time to look into date-fns v3 yet. What is it that makes it incompatible? Were there significant changes to the core functions, or is it just a matter of updating this lib's dependencies?

jerkovicl commented 9 months ago

@marnusw there are some errors when using date-fns v3 and formatInTimeZone function from date-fns-tz

import formatInTimeZone from 'date-fns-tz/formatInTimeZone';

./node_modules/date-fns-tz/esm/formatInTimeZone/index.js:1:0-61 - Error: Module not found: Error: Package path ./_lib/cloneObject/index.js is not exported from package C:\Git\projects\fiyu\frontend\node_modules\date-fns (see exports field in C:\Git\projects\fiyu\frontend\node_modules\date-fns\package.json)

./node_modules/date-fns-tz/esm/format/index.js:1:0-53 - Error: Module not found: Error: Package path ./format/index.js is not exported from package C:\Git\projects\fiyu\frontend\node_modules\date-fns (see exports field in C:\Git\projects\fiyu\frontend\node_modules\date-fns\package.json)

./node_modules/date-fns-tz/esm/toDate/index.js:1:0-57 - Error: Module not found: Error: Package path ./_lib/toInteger/index.js is not exported from package C:\Git\projects\fiyu\frontend\node_modules\date-fns (see exports field in C:\Git\projects\fiyu\frontend\node_modules\date-fns\package.json)

./node_modules/date-fns-tz/esm/toDate/index.js:2:0-101 - Error: Module not found: Error: Package path ./_lib/getTimezoneOffsetInMilliseconds/index.js is not exported from package C:\Git\projects\fiyu\frontend\node_modules\date-fns (see exports field in C:\Git\projects\fiyu\frontend\node_modules\date-fns\package.json)
woothu commented 9 months ago

Here is a list of breaking changes https://github.com/date-fns/date-fns/releases/tag/v3.0.0

joergbaier commented 9 months ago

It would be nice to match the major versioning of date-fns with this change, publish it as "v3.0.0".

StefanNedelchev commented 9 months ago

@marnusw there are some errors when using date-fns v3 and formatInTimeZone function from date-fns-tz

import formatInTimeZone from 'date-fns-tz/formatInTimeZone';

./node_modules/date-fns-tz/esm/formatInTimeZone/index.js:1:0-61 - Error: Module not found: Error: Package path ./_lib/cloneObject/index.js is not exported from package C:\Git\projects\fiyu\frontend\node_modules\date-fns (see exports field in C:\Git\projects\fiyu\frontend\node_modules\date-fns\package.json)

./node_modules/date-fns-tz/esm/format/index.js:1:0-53 - Error: Module not found: Error: Package path ./format/index.js is not exported from package C:\Git\projects\fiyu\frontend\node_modules\date-fns (see exports field in C:\Git\projects\fiyu\frontend\node_modules\date-fns\package.json)

./node_modules/date-fns-tz/esm/toDate/index.js:1:0-57 - Error: Module not found: Error: Package path ./_lib/toInteger/index.js is not exported from package C:\Git\projects\fiyu\frontend\node_modules\date-fns (see exports field in C:\Git\projects\fiyu\frontend\node_modules\date-fns\package.json)

./node_modules/date-fns-tz/esm/toDate/index.js:2:0-101 - Error: Module not found: Error: Package path ./_lib/getTimezoneOffsetInMilliseconds/index.js is not exported from package C:\Git\projects\fiyu\frontend\node_modules\date-fns (see exports field in C:\Git\projects\fiyu\frontend\node_modules\date-fns\package.json)

Yes, that's related to date-fns changing their exports. They got rid of all default exports and now you have to refactor the imports like this:

// Old
import format from 'date-fns/format'
// New
import { format } from 'date-fns/format'

So besides that I hope there aren't other breaking changes that affect date-fns-tz

jerkovicl commented 9 months ago

@StefanNedelchev already refactored imports for date-fns to new format, those errors i posted are after refactor

StefanNedelchev commented 9 months ago

@StefanNedelchev already refactored imports for date-fns to new format, those errors i posted are after refactor

Not you - the author of date-fns-tz. The library itself needs to address these changes too

oldmill1 commented 9 months ago

This library doesn't really work with date-fns 3 anymore. If you try to follow the documentation, you just get this:

./node_modules/date-fns-tz/esm/format/index.js:1:0
Module not found: Package path ./format/index.js is not exported from package /Users/ataxali/dev/jollof/node_modules/date-fns (see exports field in /Users/ataxali/dev/jollof/node_modules/date-fns/package.json)

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./node_modules/date-fns-tz/esm/index.js
./src/components/partial/Header/Desktop/TravelDeals/index.tsx
./src/components/partial/Nav/index.tsx
./src/components/partial/index.ts
./src/components/layouts/layout.tsx
./src/pages/_app.tsx

trying to just install     "date-fns": "^3.0.1",
    "date-fns-tz": "^2.0.0",
kossnocorp commented 9 months ago

@marnusw sorry for the mess! I wish I had given you a heads-up before v3.0.0

JeromeFitz commented 9 months ago

Edited

Synopsis of what may need to be addressed (Release Notes):

Other things to think about due to date-fns@3:


Found this out by trying to see if I could help migrate/upgrade date-fns-tz and it looks to be a bit more than cosmetic effort, but that all depends on what is needed.

@tuukkasp pointed out a good point that perhaps a date-fns-tz@2.0.1 release could update peerDependencies:

The stepped efforts I've done can be walked through here:

This combines some stepped approaches with a breakdown into one into a scoped short-term package:

Obviously this made some decisions, but trying to look through the code it looked to mimic a lot of the original decision to base off of date-fns. And due to their v3 change perhaps this would be the eventual intention.

Giant PRs like this are difficult (at best) to sift through, so if anything like this wants to be considered for date-fns-tz can look at how to "rework" the steps into bite-sized PR chunks a bit better, especially with lessons learned.

As of this edit though I will not have time until next week at the earliest it looks like.

rene-stesl commented 9 months ago

getting some erros trying to start my application with vite

X [ERROR] Missing "./_lib/cloneObject/index.js" specifier in "date-fns" package [plugin vite:dep-pre-bundle]         

    node_modules/vite/node_modules/esbuild/lib/main.js:1374:21:                                                      
      1374 │         let result = await callback({                                                                   
           ╵                      ^                                                                                  

    at e (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:21914:25)                      
    at n (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:21914:627)                     
    at o (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:21914:1297)                    
    at resolveExportsOrImports (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:29473:20)
    at resolveDeepImport (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:29492:31)
    at tryNodeResolve (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:29217:20)
    at Context.resolveId (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:28985:28)
    at Object.resolveId (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:63629:64)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:67637:21
    at async file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:41080:34
    at async requestCallbacks.on-resolve (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:1374:22)
    at async handleRequest (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:731:11)

  This error came from the "onResolve" callback registered here:

    node_modules/vite/node_modules/esbuild/lib/main.js:1293:20:
      1293 │       let promise = setup({
           ╵                     ^

    at setup (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:41060:19)
    at handlePlugins (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:1293:21)
    at buildOrContextImpl (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:979:5)
    at Object.buildOrContext (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:787:5)
    at D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:2197:68
    at new Promise (<anonymous>)
    at Object.context (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:2197:27)
    at Object.context (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:2037:58)
    at prepareEsbuildOptimizerRun (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:65419:35)

  The plugin "vite:dep-pre-bundle" was triggered by this import

    node_modules/date-fns-tz/esm/zonedTimeToUtc/index.js:1:24:
      1 │ import cloneObject from 'date-fns/_lib/cloneObject/index.js'
        ╵                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

X [ERROR] Missing "./_lib/cloneObject/index.js" specifier in "date-fns" package [plugin vite:dep-pre-bundle]

    node_modules/vite/node_modules/esbuild/lib/main.js:1374:21:
      1374 │         let result = await callback({
           ╵                      ^

    at e (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:21914:25)
    at n (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:21914:627)
    at o (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:21914:1297)
    at resolveExportsOrImports (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:29473:20)
    at resolveDeepImport (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:29492:31)
    at tryNodeResolve (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:29217:20)
    at Context.resolveId (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:28985:28)
    at Object.resolveId (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:63629:64)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:67637:21
    at async file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:41080:34
    at async requestCallbacks.on-resolve (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:1374:22)
    at async handleRequest (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:731:11)

  This error came from the "onResolve" callback registered here:

    node_modules/vite/node_modules/esbuild/lib/main.js:1293:20:
      1293 │       let promise = setup({
           ╵                     ^

    at setup (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:41060:19)
    at handlePlugins (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:1293:21)
    at buildOrContextImpl (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:979:5)
    at Object.buildOrContext (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:787:5)
    at D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:2197:68
    at new Promise (<anonymous>)
    at Object.context (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:2197:27)
    at Object.context (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:2037:58)
    at prepareEsbuildOptimizerRun (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:65419:35)

  The plugin "vite:dep-pre-bundle" was triggered by this import

    node_modules/date-fns-tz/esm/formatInTimeZone/index.js:1:24:
      1 │ import cloneObject from 'date-fns/_lib/cloneObject/index.js'
        ╵                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

X [ERROR] Missing "./_lib/toInteger/index.js" specifier in "date-fns" package [plugin vite:dep-pre-bundle]

    node_modules/vite/node_modules/esbuild/lib/main.js:1374:21:
      1374 │         let result = await callback({
           ╵                      ^

    at e (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:21914:25)
    at n (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:21914:627)
    at o (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:21914:1297)
    at resolveExportsOrImports (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:29473:20)
    at resolveDeepImport (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:29492:31)
    at tryNodeResolve (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:29217:20)
    at Context.resolveId (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:28985:28)
    at Object.resolveId (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:63629:64)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:67637:21
    at async file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:41080:34
    at async requestCallbacks.on-resolve (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:1374:22)
    at async handleRequest (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:731:11)

  This error came from the "onResolve" callback registered here:

    node_modules/vite/node_modules/esbuild/lib/main.js:1293:20:
      1293 │       let promise = setup({
           ╵                     ^

    at setup (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:41060:19)
    at handlePlugins (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:1293:21)
    at buildOrContextImpl (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:979:5)
    at Object.buildOrContext (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:787:5)
    at D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:2197:68
    at new Promise (<anonymous>)
    at Object.context (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:2197:27)
    at Object.context (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:2037:58)
    at prepareEsbuildOptimizerRun (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:65419:35)

  The plugin "vite:dep-pre-bundle" was triggered by this import

    node_modules/date-fns-tz/esm/toDate/index.js:1:22:
      1 │ import toInteger from 'date-fns/_lib/toInteger/index.js'
        ╵                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

X [ERROR] Missing "./format/index.js" specifier in "date-fns" package [plugin vite:dep-pre-bundle]

    node_modules/vite/node_modules/esbuild/lib/main.js:1374:21:
      1374 │         let result = await callback({
           ╵                      ^

    at e (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:21914:25)
    at n (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:21914:627)
    at o (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:21914:1297)
    at resolveExportsOrImports (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:29473:20)
    at resolveDeepImport (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:29492:31)
    at tryNodeResolve (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:29217:20)
    at Context.resolveId (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:28985:28)
    at Object.resolveId (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:63629:64)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:67637:21
    at async file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:41080:34
    at async requestCallbacks.on-resolve (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:1374:22)
    at async handleRequest (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:731:11)

  This error came from the "onResolve" callback registered here:

    node_modules/vite/node_modules/esbuild/lib/main.js:1293:20:
      1293 │       let promise = setup({
           ╵                     ^

    at setup (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:41060:19)
    at handlePlugins (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:1293:21)
    at buildOrContextImpl (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:979:5)
    at Object.buildOrContext (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:787:5)
    at D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:2197:68
    at new Promise (<anonymous>)
    at Object.context (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:2197:27)
    at Object.context (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:2037:58)
    at prepareEsbuildOptimizerRun (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:65419:35)

  The plugin "vite:dep-pre-bundle" was triggered by this import

    node_modules/date-fns-tz/esm/format/index.js:1:26:
      1 │ import dateFnsFormat from 'date-fns/format/index.js'
        ╵                           ~~~~~~~~~~~~~~~~~~~~~~~~~~

X [ERROR] Missing "./_lib/getTimezoneOffsetInMilliseconds/index.js" specifier in "date-fns" package [plugin vite:dep-pre-bundle]

    node_modules/vite/node_modules/esbuild/lib/main.js:1374:21:
      1374 │         let result = await callback({
           ╵                      ^

    at e (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:21914:25)
    at n (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:21914:627)
    at o (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:21914:1297)
    at resolveExportsOrImports (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:29473:20)
    at resolveDeepImport (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:29492:31)
    at tryNodeResolve (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:29217:20)
    at Context.resolveId (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:28985:28)
    at Object.resolveId (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:63629:64)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:67637:21
    at async file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:41080:34
    at async requestCallbacks.on-resolve (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:1374:22)
    at async handleRequest (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:731:11)

  This error came from the "onResolve" callback registered here:

    node_modules/vite/node_modules/esbuild/lib/main.js:1293:20:
      1293 │       let promise = setup({
           ╵                     ^

    at setup (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:41060:19)
    at handlePlugins (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:1293:21)
    at buildOrContextImpl (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:979:5)
    at Object.buildOrContext (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:787:5)
    at D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:2197:68
    at new Promise (<anonymous>)
    at Object.context (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:2197:27)
    at Object.context (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:2037:58)
    at prepareEsbuildOptimizerRun (file:///D:/WORK/frontend/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:65419:35)

  The plugin "vite:dep-pre-bundle" was triggered by this import

    node_modules/date-fns-tz/esm/toDate/index.js:2:44:
      2 │ import getTimezoneOffsetInMilliseconds from 'date-fns/_lib/getTimezoneOffsetInMilliseconds/index.js'
        ╵                                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:1650
  let error = new Error(text);
              ^

Error: Build failed with 5 errors:
node_modules/vite/node_modules/esbuild/lib/main.js:1374:21: ERROR: [plugin: vite:dep-pre-bundle] Missing "./_lib/cloneObject/index.js" specifier in "date-fns" package
node_modules/vite/node_modules/esbuild/lib/main.js:1374:21: ERROR: [plugin: vite:dep-pre-bundle] Missing "./_lib/cloneObject/index.js" specifier in "date-fns" package
node_modules/vite/node_modules/esbuild/lib/main.js:1374:21: ERROR: [plugin: vite:dep-pre-bundle] Missing "./_lib/getTimezoneOffsetInMilliseconds/index.js" specifier in "date-fns" package
node_modules/vite/node_modules/esbuild/lib/main.js:1374:21: ERROR: [plugin: vite:dep-pre-bundle] Missing "./_lib/toInteger/index.js" specifier in "date-fns" package
node_modules/vite/node_modules/esbuild/lib/main.js:1374:21: ERROR: [plugin: vite:dep-pre-bundle] Missing "./format/index.js" specifier in "date-fns" package
    at failureErrorWithLog (D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:1650:15)
    at D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:1059:25
    at D:\WORK\frontend\node_modules\vite\node_modules\esbuild\lib\main.js:1526:9
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  errors: [Getter/Setter],
  warnings: [Getter/Setter]
}

Node.js v20.9.0

Process finished with exit code 1
RuslanUshakov commented 9 months ago

is there any workaround to make it work at this point?

JeromeFitz commented 9 months ago

The move from date-fns@2 to date-fns@3 has introduced 💥 breaking changes 💥. Which is why the authors identified the breaking/major version change and accompanying release notes.

For those affected and use date-fns-tz@2 the best solution for you right now is to downgrade to date-fns@2.

Then at a later date when date-fns-tz has been updated to be compatible and work with date-fns@3 – that would be the time to upgrade both together.

--

Sharing a bit more about semantic versioning 🔗 if it is helpful to anyone.

In the case for date-fns@3 the x in the x.y.z version format is the identifier. This symbolizes to users of the package and other packages that rely on/ work with it that before you make this update – you may have some work to do. Whereas the y or z in the x.y.z version may mean (but not always) that you do not.

tuukkasp commented 9 months ago

It would probably be good to release v2.0.1 of this that caps the date-fns dependency to ^2 for all the automated systems that keep wanting to upgrade it currently like dependabot

gregg-cbs commented 9 months ago

This has been a help! Just a note going back a version caused errors in my code which I had to fix, nothing too major.

I uninstalled date-fns and date-fns-tz: npm uninstall date-fns date-fns-tz

I reinstalled both at v2: npm i date-fns@2 date-fns-tz@2

christopherklint97 commented 9 months ago

I created a PR to update date-fns to v3. Right now some tests are failing due to a webpack loader missing. Any help is much appreciated!

https://github.com/marnusw/date-fns-tz/pull/265

JeromeFitz commented 9 months ago

Sweet @christopherklint97 ! I shared some findings on the upgrade path as I saw it earlier in the thread if it is helpful, and will try and pull down your code and assist in review later today:

I did publish a stop-gap (for myself) at:

Since it did a lot more than just the minimal upgrade did not think it was in a state to do a PR here without understanding the desired path forward for the library. But may be of short-term use for some folks.

hejtmii commented 9 months ago

Hi, if anyone needs workaround until there is a newer version of date-fns-tz, the workaround is to add v2 explicitly to your root package.json

"date-fns": "2.30.0",

The problem is caused by date-fns-tz having defined peer dependency with >= which automatically bumps even the major version (which happened 2 weeks ago when 3.0.0. was released)

"node_modules/date-fns-tz": {
      "version": "2.0.0",
      ...
      "peerDependencies": {
        "date-fns": ">=2.0.0"
      }
    },

@RuslanUshakov

rphlmr commented 8 months ago

Hello 👋

If like me you need the last date-fns version and date-fns-tz, there is a temporary solution.

You need patch-package (https://www.npmjs.com/package/patch-package). Follow their instructions but in short:

At this point you should have a patches/date-fns-tz+2.0.0.patch file created:

diff --git a/node_modules/date-fns-tz/package.json b/node_modules/date-fns-tz/package.json
index 034e083..7576fc6 100644
--- a/node_modules/date-fns-tz/package.json
+++ b/node_modules/date-fns-tz/package.json
@@ -120,7 +120,7 @@
     ]
   },
   "peerDependencies": {
-    "date-fns": ">=2.0.0"
+    "date-fns": "2.x"
   },
   "devDependencies": {
     "@babel/cli": "^7.15.4",

Now, install date-fns again with npm i date-fns-v3@npm:date-fns date-fns@npm:date-fns@2. You'll have 2 packages:

Remove your package-lock.json and node_modules and re-install (to have a fresh node_modules).

StefanNedelchev commented 8 months ago

Remove your package.json and node_modules and re-install (to have a fresh node_modules).

I believe you mean package-lock.json?

zymotik commented 8 months ago

I added an override to my package.json instead:

{
 "name": "your-project-name",
  ...
  "overrides": {
    "date-fns": "^2.0.0"
  }
}

After adding it, run npm install. Check if it's working with: npm ls date-fns. You should see:

you-project-name@0.1.0 /home/user/your-project-repo-dir
└─┬ date-fns-tz@2.0.0
  └── date-fns@2.30.0 overridden
zymotik commented 8 months ago

It would probably be good to release v2.0.1 of this that caps the date-fns dependency to ^2 for all the automated systems that keep wanting to upgrade it currently like dependabot

This would be very helpful to those that don't know how to fix this!

okcoker commented 8 months ago

Also used patch-package as mentioned here, but I went a step further and got things working with date-fns v3 (specifically 3.2.0) for my project. Use at your own risk, but here are the patch files I'm using:

patches/date-fns+3.2.0.patch

diff --git a/node_modules/date-fns/package.json b/node_modules/date-fns/package.json
index 3493e27..b8406b5 100644
--- a/node_modules/date-fns/package.json
+++ b/node_modules/date-fns/package.json
@@ -48,6 +48,16 @@
         "default": "./locale.mjs"
       }
     },
+    "./_lib/getTimezoneOffsetInMilliseconds": {
+      "require": {
+        "types": "./_lib/getTimezoneOffsetInMilliseconds.d.ts",
+        "default": "./_lib/getTimezoneOffsetInMilliseconds.js"
+      },
+      "import": {
+        "types": "./_lib/getTimezoneOffsetInMilliseconds.d.mts",
+        "default": "./_lib/getTimezoneOffsetInMilliseconds.mjs"
+      }
+    },
     "./fp": {
       "require": {
         "types": "./fp.d.ts",

patches/date-fns-tz+2.0.0.patch

diff --git a/node_modules/date-fns-tz/_lib/toInteger/index.js b/node_modules/date-fns-tz/_lib/toInteger/index.js
new file mode 100644
index 0000000..dcceb65
--- /dev/null
+++ b/node_modules/date-fns-tz/_lib/toInteger/index.js
@@ -0,0 +1,27 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+  value: true
+});
+exports.default = toInteger;
+
+function toInteger(
+    dirtyNumber
+  ) {
+    if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) {
+      return NaN;
+    }
+
+    const number = Number(dirtyNumber)
+
+    if (isNaN(number)) {
+      return number;
+    }
+
+    return (number < 0
+      ? Math.ceil(number)
+      : Math.floor(number));
+  }
+
+
+module.exports = exports.default;
diff --git a/node_modules/date-fns-tz/esm/_lib/toInteger/index.js b/node_modules/date-fns-tz/esm/_lib/toInteger/index.js
new file mode 100644
index 0000000..38cb148
--- /dev/null
+++ b/node_modules/date-fns-tz/esm/_lib/toInteger/index.js
@@ -0,0 +1,17 @@
+export default function toInteger(
+    dirtyNumber
+  ) {
+    if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) {
+      return NaN;
+    }
+
+    const number = Number(dirtyNumber)
+
+    if (isNaN(number)) {
+      return number;
+    }
+
+    return (number < 0
+      ? Math.ceil(number)
+      : Math.floor(number));
+  }
diff --git a/node_modules/date-fns-tz/esm/formatInTimeZone/index.js b/node_modules/date-fns-tz/esm/formatInTimeZone/index.js
index bbb2c4e..b29229a 100644
--- a/node_modules/date-fns-tz/esm/formatInTimeZone/index.js
+++ b/node_modules/date-fns-tz/esm/formatInTimeZone/index.js
@@ -1,4 +1,3 @@
-import cloneObject from 'date-fns/_lib/cloneObject/index.js'
 import format from '../format/index.js'
 import utcToZonedTime from '../utcToZonedTime/index.js'

@@ -25,7 +24,7 @@ import utcToZonedTime from '../utcToZonedTime/index.js'
  * @returns {String} the formatted date string
  */
 export default function formatInTimeZone(date, timeZone, formatStr, options) {
-  var extendedOptions = cloneObject(options)
+  var extendedOptions = {...options};
   extendedOptions.timeZone = timeZone
   return format(utcToZonedTime(date, timeZone), formatStr, extendedOptions)
 }
diff --git a/node_modules/date-fns-tz/esm/toDate/index.js b/node_modules/date-fns-tz/esm/toDate/index.js
index 6acea0e..8cc6529 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 '../_lib/toInteger/index.js'
+import getTimezoneOffsetInMilliseconds from 'date-fns/_lib/getTimezoneOffsetInMilliseconds.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..f343aa5 100644
--- a/node_modules/date-fns-tz/esm/zonedTimeToUtc/index.js
+++ b/node_modules/date-fns-tz/esm/zonedTimeToUtc/index.js
@@ -1,4 +1,3 @@
-import cloneObject from 'date-fns/_lib/cloneObject/index.js'
 import toDate from '../toDate/index.js'
 import tzPattern from '../_lib/tzPattern/index.js'
 import tzParseTimezone from '../_lib/tzParseTimezone/index.js'
@@ -30,7 +29,7 @@ import newDateUTC from '../_lib/newDateUTC/index.js'
  */
 export default function zonedTimeToUtc(date, timeZone, options) {
   if (typeof date === 'string' && !date.match(tzPattern)) {
-    var extendedOptions = cloneObject(options)
+    var extendedOptions = {...options}
     extendedOptions.timeZone = timeZone
     return toDate(date, extendedOptions)
   }
diff --git a/node_modules/date-fns-tz/format/index.js b/node_modules/date-fns-tz/format/index.js
index 0ffeff8..b7ba182 100644
--- a/node_modules/date-fns-tz/format/index.js
+++ b/node_modules/date-fns-tz/format/index.js
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
 });
 exports.default = format;

-var _index = _interopRequireDefault(require("date-fns/format/index.js"));
+var _index = _interopRequireDefault(require("date-fns"));

 var _index2 = _interopRequireDefault(require("./formatters/index.js"));

@@ -348,7 +348,7 @@ function format(dirtyDate, dirtyFormatStr, dirtyOptions) {
     }, formatStr);
   }

-  return (0, _index.default)(dirtyDate, formatStr, options);
+  return _index.default.format(dirtyDate, formatStr, options);
 }

 module.exports = exports.default;
diff --git a/node_modules/date-fns-tz/formatInTimeZone/index.js b/node_modules/date-fns-tz/formatInTimeZone/index.js
index ca93886..4429029 100644
--- a/node_modules/date-fns-tz/formatInTimeZone/index.js
+++ b/node_modules/date-fns-tz/formatInTimeZone/index.js
@@ -5,8 +5,6 @@ Object.defineProperty(exports, "__esModule", {
 });
 exports.default = formatInTimeZone;

-var _index = _interopRequireDefault(require("date-fns/_lib/cloneObject/index.js"));
-
 var _index2 = _interopRequireDefault(require("../format/index.js"));

 var _index3 = _interopRequireDefault(require("../utcToZonedTime/index.js"));
@@ -36,7 +34,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
  * @returns {String} the formatted date string
  */
 function formatInTimeZone(date, timeZone, formatStr, options) {
-  var extendedOptions = (0, _index.default)(options);
+  var extendedOptions = {...options};
   extendedOptions.timeZone = timeZone;
   return (0, _index2.default)((0, _index3.default)(date, timeZone), formatStr, extendedOptions);
 }
diff --git a/node_modules/date-fns-tz/toDate/index.js b/node_modules/date-fns-tz/toDate/index.js
index 6c1aaaa..4eaeaaa 100644
--- a/node_modules/date-fns-tz/toDate/index.js
+++ b/node_modules/date-fns-tz/toDate/index.js
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
 });
 exports.default = toDate;

-var _index = _interopRequireDefault(require("date-fns/_lib/toInteger/index.js"));
+var _index = _interopRequireDefault(require("../_lib/toInteger/index.js"));

-var _index2 = _interopRequireDefault(require("date-fns/_lib/getTimezoneOffsetInMilliseconds/index.js"));
+var _index2 = _interopRequireDefault(require("date-fns/_lib/getTimezoneOffsetInMilliseconds"));

 var _index3 = _interopRequireDefault(require("../_lib/tzParseTimezone/index.js"));

diff --git a/node_modules/date-fns-tz/zonedTimeToUtc/index.js b/node_modules/date-fns-tz/zonedTimeToUtc/index.js
index 3739d26..3d6535e 100644
--- a/node_modules/date-fns-tz/zonedTimeToUtc/index.js
+++ b/node_modules/date-fns-tz/zonedTimeToUtc/index.js
@@ -5,8 +5,6 @@ Object.defineProperty(exports, "__esModule", {
 });
 exports.default = zonedTimeToUtc;

-var _index = _interopRequireDefault(require("date-fns/_lib/cloneObject/index.js"));
-
 var _index2 = _interopRequireDefault(require("../toDate/index.js"));

 var _index3 = _interopRequireDefault(require("../_lib/tzPattern/index.js"));
@@ -43,7 +41,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
  */
 function zonedTimeToUtc(date, timeZone, options) {
   if (typeof date === 'string' && !date.match(_index3.default)) {
-    var extendedOptions = (0, _index.default)(options);
+    var extendedOptions = {...options};
     extendedOptions.timeZone = timeZone;
     return (0, _index2.default)(date, extendedOptions);
   }
walterholohan commented 7 months ago

@marnusw any timeline on when you will get a chance to release new version that supports date-fns v3?

drewbrend commented 7 months ago

@marnusw Can you please merge this approved PR to fix the dependency issue in V2 until V3 is released? https://github.com/marnusw/date-fns-tz/pull/267

Myself and many others are suffering a great amount of headaches from this issue, this tiny PR simply corrects the date-fns version range to not allow V3 which would fix this issue completely for V2 users.

WayneEllery commented 7 months ago

this tiny PR simply corrects the date-fns version range to not allow V3 which would fix this issue completely.

No this is not correct. The PR you posted will not allow date-fns v3 to be used by date-fns-tz v2 but it wont fix this issue of using date-fns v3 with date-fns-tz

drewbrend commented 7 months ago

No this is not correct. The PR you posted will not allow date-fns v3 to be used by date-fns-tz v2 but it wont fix this issue of using date-fns v3 with date-fns-tz

It means the date-fns-tz V2 will be using date-fns V2, which it is compatible with. You are correct that it will not make it compatible with V3. The example scenario this fixes is in that PR's description.

I edited my previous message for clarity to say for V2 users specifically.

chrisspiegl commented 7 months ago

I am adding my support for this PR (https://github.com/marnusw/date-fns-tz/pull/267) to be merged and released. It would be massively helpful to mark this package v2 to only install the proper date-fns v2 versions.

I understand it's not making it compatible, but at least it makes it easy to continue to depend on v2 of all the things. And then, with time, date-fns-tz can be made compatible with date-fns v3.

Stf-F commented 6 months ago

I am a bit confused by what's available or not. I came across date-fns-tz-v3 and hoped that it would address the issues mentioned here.

But it didn't. I still had an import issue:

Package subpath './format/index.js' is not defined by "exports" in [my_path]/node_modules/date-fns/package.json imported from [my_path]/node_modules/date-fns-tz/esm/format/index.js

Is this package meant to be a port compatible with date-fns v3?

donaldpipowitch commented 6 months ago

Can the issue be re-opened? It's a bit misleading right now, because date-fns v3 is not yet supported, right?

WayneEllery commented 6 months ago

Yeah, I believe this shouldn't be closed as v3 is still not supported

mani444 commented 6 months ago

I am also facing the same issue and I have used this temporary solution for now. This is working!!!

Hello 👋

If like me you need the last date-fns version and date-fns-tz, there is a temporary solution.

You need patch-package (https://www.npmjs.com/package/patch-package). Follow their instructions but in short:

  • add "postinstall": "patch-package" in your package.json scripts
  • edit node_modules/date-fns-tz/package.json and change its "date-fns" peerDependencies to "2.x"
  • run npx patch-package date-fns-tz

At this point you should have a patches/date-fns-tz+2.0.0.patch file created:

diff --git a/node_modules/date-fns-tz/package.json b/node_modules/date-fns-tz/package.json
index 034e083..7576fc6 100644
--- a/node_modules/date-fns-tz/package.json
+++ b/node_modules/date-fns-tz/package.json
@@ -120,7 +120,7 @@
     ]
   },
   "peerDependencies": {
-    "date-fns": ">=2.0.0"
+    "date-fns": "2.x"
   },
   "devDependencies": {
     "@babel/cli": "^7.15.4",

Now, install date-fns again with npm i date-fns-v3@npm:date-fns date-fns@npm:date-fns@2. You'll have 2 packages:

  • date-fns-v3 (to use in your code) => import { isBefore, isEqual } from "date-fns-v3"
  • The 'old' date-fns(v2) for date-fns-tz

Remove your package-lock.json and node_modules and re-install (to have a fresh node_modules).

drazik commented 6 months ago

I believe it has been automatically closed when #267 has been merged. I also think it should be reopened, because even if #267 is a good step to help mark the package as compatible with date-fns@2 only, it doesn't solve the initial issue of it not being compatible with date-fns@3

265 is the one that will fix this issue when it's merged

marnusw commented 6 months ago

v2.0.1 has been published which locks the date-fns version to 2. v3.0.0 will follow.

marnusw commented 6 months ago

3.0.0-beta.0 is available which supports date-fns@3.

russcarver commented 6 months ago

With these two installed:

"date-fns": "3.6.0",
"date-fns-tz": "3.0.0-beta.0",

I am getting these errors upon build:

./node_modules/date-fns-tz/esm/format/index.js:1:0-61 - Error: Module not found: Error: Package path ./format.js is not exported from package /node_modules/date-fns (see exports field in /node_modules/date-fns/package.json)

./node_modules/date-fns-tz/esm/toDate/index.js:1:0-99 - Error: Module not found: Error: Package path ./_lib/getTimezoneOffsetInMilliseconds.js is not exported from package /node_modules/date-fns (see exports field in /node_modules/date-fns/package.json)

voors commented 6 months ago

The same problem here, any ideas? because i'm downgrade version to v2 and many methods not exists :(

sorodrigo commented 6 months ago

I used this patch-package in the meantime.

diff --git a/node_modules/date-fns/package.json b/node_modules/date-fns/package.json
index 2af042a..b444ab8 100644
--- a/node_modules/date-fns/package.json
+++ b/node_modules/date-fns/package.json
@@ -18,6 +18,16 @@
   "module": "./index.mjs",
   "exports": {
     "./package.json": "./package.json",
+    "./_lib/getTimezoneOffsetInMilliseconds.js": {
+      "require": {
+        "types": "./_lib/getTimezoneOffsetInMilliseconds.d.ts",
+        "default": "./_lib/getTimezoneOffsetInMilliseconds.js"
+      },
+      "import": {
+        "types": "./_lib/getTimezoneOffsetInMilliseconds.d.mts",
+        "default": "./_lib/getTimezoneOffsetInMilliseconds.mjs"
+      }
+    },
     ".": {
       "require": {
         "types": "./index.d.ts",
@@ -678,6 +688,16 @@
         "default": "./endOfYesterday.mjs"
       }
     },
+    "./format.js": {
+      "require": {
+        "types": "./format.d.ts",
+        "default": "./format.js"
+      },
+      "import": {
+        "types": "./format.d.mts",
+        "default": "./format.mjs"
+      }
+    },
     "./format": {
       "require": {
         "types": "./format.d.ts",

imagen

marnusw commented 6 months ago

@russcarver @voors please try 3.0.0-beta.1 and see if the imports work now.

Edit: I think it's fixed for format, but might still not be for getTimezoneOffsetInMilliseconds which isn't exported by date-fns/package.json. It a small enough function though, I'll just copy it into date-fns-tz.

deathemperor commented 6 months ago

@russcarver @voors please try 3.0.0-beta.1 and see if the imports work now.

Edit: I think it's fixed for format, but might still not be for getTimezoneOffsetInMilliseconds which isn't exported by date-fns/package.json. It a small enough function though, I'll just copy it into date-fns-tz.

confirmed getTimezoneOffsetInMilliseconds is missing

error during build:
Error: [commonjs--resolver] Missing "./_lib/getTimezoneOffsetInMilliseconds" specifier in "date-fns" package
marnusw commented 6 months ago

I think the best solution is literally just copying the function from date-fns into date-fns-tz. I'll do it this week, but if someone beats me to it with a PR that will be even faster.

deathemperor commented 6 months ago

I think the best solution is literally just copying the function from date-fns into date-fns-tz. I'll do it this week, but if someone beats me to it with a PR that will be even faster.

@gugu just opened the PR https://github.com/marnusw/date-fns-tz/pull/272

marnusw commented 6 months ago

Please give 3.0.0-beta.2 a try to see if the issue has been resolved.

orianlevy commented 6 months ago

It’s working 🍾

Pinqvin commented 6 months ago

It seems like 3.0.0-beta.2 is still trying to access some internal implementation details of date-fns that are no longer exposed. I'm getting this error in our build:

error during build:
Error: [commonjs--resolver] Missing "./fp/_lib/convertToFP" specifier in "date-fns" package

Looks like it's being imported here, I suppose these versions aren't as widely used.

marnusw commented 6 months ago

@Pinqvin I'll take another look. I only merged the PR that was created thus far. I'll ensure all the usages are cleaned up.

Actually, yes, that convert to fp is probably the last one and would only affect those using the FP variant.

kossnocorp commented 6 months ago

@marnusw I don't know the details of the problem, but if you need any internals exposed, I can work on it. It wasn't my intention to conceal anything, here's what I did for calendar adapters: https://github.com/date-fns/date-fns/blob/main/src/format/index.ts#L20-L22

kossnocorp commented 6 months ago

@marnusw also, I understand how open source can be a burden and priorities change, so if you feel like it, I can overtake the maintenance of the package and/or merge functionality into the core. I would do it on the terms that seem most fair to you.

I have to mention first that despite the pile of requests, the timeline of date-fns-tz adopting v3 is absolutely fine, and I hope you're not feeling much pressure. I think you're doing a great job, and working on open-source on your terms is okay. I know how it feels as I was in such a position many times.

Even though time zones were always on my mind, having independent date-fns-tz allowed me to focus on the core library, which always had something going on. I'm very grateful for that. I deeply respect your work, so I never tried to compete with or reimplement anything from this library.

I have plans to extend the work I did with @date-fns/utc and do something similar with timezones, i.e., TZDate. However, I didn't plan to have functional-style timezone functions in the core even though I think it will benefit the users.

I believe that it's the best strategy for everyone, from users to maintainers, as it nourishes the ecosystem instead of killing it with fierce competition.

marnusw commented 6 months ago

@Pinqvin finally in 3.0.0-beta.3 the fp variant should work as well!

Pinqvin commented 6 months ago

And it does indeed build now, thank you!