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

Support for date-fns v3 #260

Closed
woothu opened this issue Dec 18, 2023 · 55 comments · Fixed by #267 or #273
Closed

Support for date-fns v3 #260

woothu opened this issue Dec 18, 2023 · 55 comments · Fixed by #267 or #273

Comments

@woothu
Copy link

woothu commented Dec 18, 2023

Date-fns just released a stable version 3:
image

Is this package going to support the new version?

@marnusw
Copy link
Owner

marnusw commented Dec 18, 2023

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
Copy link

jerkovicl commented Dec 18, 2023

@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
Copy link
Author

woothu commented Dec 18, 2023

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

@joergbaier
Copy link

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

@StefanNedelchev
Copy link

StefanNedelchev commented Dec 19, 2023

@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
Copy link

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

@StefanNedelchev
Copy link

@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
Copy link

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
Copy link

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

@JeromeFitz
Copy link

JeromeFitz commented Dec 21, 2023

Edited

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

  • Moved to named exports instead of default
  • Account for functions that are no longer exported from date-fns@3 that were in date-fns@2
    • assign
    • cloneObject
    • toInteger
    • convertToFp (part of build process)
  • If move cloneObject to lodash/cloneDeep (or preferably lodash.clonedeep and ship with) and pass an empty object fallback this should suffice
  • Instead of toInteger make it Number() and should be good (hat-tip @christopherklint97 )
  • convertToFp does look to be part of it after all (no types are exported from date-fns though understandably)

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

  • Changed how they do ESM where they now serve CommonJS/ESM via js|mjs
  • constants is now its own import date-fns/constants
  • Focused on TypeScript checking to deal with function scenarios
    • Reduced testing, and enables functions to be simplified / slimmed
  • And of course ... a lot more heh.

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:

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

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:

  • @jeromefitz/date-fns-tz, whose intent is to be a testing stop-gap only.

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
Copy link

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
Copy link

RuslanUshakov commented Dec 22, 2023

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

@JeromeFitz
Copy link

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.

  • date-fns-tz@2 out of the box is not able to work with date-fns@3 due to these breaking changes.

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

  • This would be the suggested workaround.

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
Copy link

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
Copy link

gregg-cbs commented Dec 24, 2023

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
Copy link
Contributor

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!

#265

@JeromeFitz
Copy link

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.

@WayneEllery
Copy link

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

@mani444
Copy link

mani444 commented Mar 7, 2024

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
Copy link

drazik commented Mar 7, 2024

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 marnusw reopened this Mar 9, 2024
@marnusw
Copy link
Owner

marnusw commented Mar 9, 2024

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

belanglos added a commit to KTH/kursinfo-web that referenced this issue Mar 14, 2024
This PR is updating minor/patch updates as well as a couple of major updates.

The following dependencies are left unchanged.

- `date-fns`, because `date-fns-tz` is not compatible with it yet (see marnusw/date-fns-tz#260) 
- `prettier-2` only exists as a temporary workaround and will not be needed anymore as soon as `jest@30` is released. (see jestjs/jest#14305) 

```
 date-fns            ^2.30.0  →  ^3.4.0
 prettier-2  npm:prettier@^2  →      ^3
```
@marnusw
Copy link
Owner

marnusw commented Mar 18, 2024

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

@marnusw marnusw closed this as completed Mar 18, 2024
@russcarver
Copy link

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
Copy link

voors commented Mar 22, 2024

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

@sorodrigo
Copy link

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
Copy link
Owner

marnusw commented Mar 22, 2024

@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
Copy link

@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
Copy link
Owner

marnusw commented Mar 23, 2024

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
Copy link

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 #272

@marnusw
Copy link
Owner

marnusw commented Mar 26, 2024

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

@orianlevy
Copy link

It’s working 🍾

@Pinqvin
Copy link

Pinqvin commented Mar 26, 2024

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
Copy link
Owner

marnusw commented Mar 26, 2024

@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
Copy link

@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
Copy link

@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
Copy link
Owner

marnusw commented Mar 28, 2024

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

@Pinqvin
Copy link

Pinqvin commented Apr 2, 2024

And it does indeed build now, thank you!

@marnusw
Copy link
Owner

marnusw commented Apr 2, 2024

Please watch #273 for the official v3.0.0 release.

@marnusw marnusw mentioned this issue Apr 6, 2024
4 tasks
@marnusw
Copy link
Owner

marnusw commented Apr 6, 2024

v3.0.0 has been released.

@emanoj1
Copy link

emanoj1 commented May 26, 2024

Note: I am learning to code and hence not experienced enough.

In my package.json, I have the dependencies showing:
"date-fns": "^3.6.0",
"date-fns-tz": "^3.1.3",

Do I need to replace it with another version?

I am getting the below errors:
/node_modules/date-fns-tz/formatInTimeZone/index.js
/node_modules/date-fns-tz/toDate/index.js
node_modules/date-fns-tz/zonedTimeToUtc/index.js

@geisterfurz007
Copy link

Have you read the changelog with regards to the breaking changes? https://github.com/marnusw/date-fns-tz/blob/master/CHANGELOG.md#v300-6-april-2024

@emanoj1

@emanoj1
Copy link

emanoj1 commented May 26, 2024

https://github.com/marnusw/date-fns-tz/blob/master/CHANGELOG.md#v300-6-april-2024

Thank you very much for the reply! I went through the link you mentioned but can't figure out which one in the list I should be looking at.

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

Successfully merging a pull request may close this issue.