dayjs: 🎁 2.0 Milestones【Breaking Change】

We want to make some changes to make Day.js modern and in a standard JS way.

And this would be a breaking change because of these changes below:

Make TypeScript definition the same behavior as JS code

Update types/index.d.ts to export default dayjs;

Mark the correct ES6 Module entry

<del>Update package.json “module” to “esm/index”, (won’t introduce in “dayjs”, see https://github.com/iamkun/dayjs/issues/1281#issuecomment-754381268)</del>

Publish a new NPM package, maybe “dayjs-esm” to ship an ESM module with package.json module entry pointed to. ref https://github.com/iamkun/dayjs/issues/1242#issuecomment-734321931

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 15
  • Comments: 37 (13 by maintainers)

Commits related to this issue

Most upvoted comments

Publish a new NPM package, maybe “dayjs-esm” to ship an ESM module with package.json module entry pointed to. ref #1242 (comment)

For 2.0, I think ESM should be the default. That is the way the whole world is moving. Then we could create dayjs-umd or whatever if it’s really necessary to have multiple packages

Any news on this 2.0 version ?

This change in 1.10.1 add ES6 Module Support, package.json module point to “esm/index.js” (#1298) (f63375d)

really has an unexpected breaking change, and that’s of course not what we want.

I am planning to revert this change in the next release 1.10.2 and delete the “module” entry.

Besides, maybe there’s no need for Day.js to support ESM bundle, this would only introduce some conflict but no benefits in the tree shaking. A better way might be a separate npm package (like “dayjs-esm”) to ship an ESM package.

I’m going to +1 here to say that unfortunately this dayjs update broke the build (while preparing a 1.0 release) and we had to lock the version to 1.9.6 (I saw someone had success with 1.9.7 too).

Thanks for doing better TypeScript support and also for the dayjs package itself, @iamkun. OSS does not get enough positive support - thanks for doing this for all of us who use the package on many projects and only come to Github to figure out what broke the build.

Thanks!

I wanna point out, the recent typescript changes done in 1.10 actually broke in my project with the way that it was documented online on how to install/use dayjs in angular

import * as updateLocale from 'dayjs/plugin/updateLocale'
import * as relativeTime from 'dayjs/plugin/relativeTime'
import * as LocalizedFormat from 'dayjs/plugin/localizedFormat'
import * as dayjs from 'dayjs'
dayjs.extend(LocalizedFormat)
dayjs.extend(relativeTime)
dayjs.extend(updateLocale)
dayjs.locale('is')

Error: "export 'extend' (imported as 'dayjs') was not found in 'dayjs'

So there already has been breaking changes, especially with usage on typescript so might as well just push these changes over since people are gonna have to update their projects

I wanna point out, the recent typescript changes done in 1.10 actually broke in my project with the way that it was documented online on how to install/use dayjs in angular

import * as updateLocale from 'dayjs/plugin/updateLocale'
import * as relativeTime from 'dayjs/plugin/relativeTime'
import * as LocalizedFormat from 'dayjs/plugin/localizedFormat'
import * as dayjs from 'dayjs'
dayjs.extend(LocalizedFormat)
dayjs.extend(relativeTime)
dayjs.extend(updateLocale)
dayjs.locale('is')

Error: "export 'extend' (imported as 'dayjs') was not found in 'dayjs' So there already has been breaking changes, especially with usage on typescript so might as well just push these changes over since people are gonna have to update their projects

@TheThing I have the same issue. did you fixed yours? How?

I tried something like this:

import dayjs, { extend } from 'dayjs'

I just made the version in package.json hard value to the last known working version: 1.9.7 like so: "dayjs": "1.9.7",

Github diff image

If dayjs is gonna add breaking changes without increasing their major version, I might as well just lock the version 😃

I wanna point out, the recent typescript changes done in 1.10 actually broke in my project with the way that it was documented online on how to install/use dayjs in angular

import * as updateLocale from 'dayjs/plugin/updateLocale'
import * as relativeTime from 'dayjs/plugin/relativeTime'
import * as LocalizedFormat from 'dayjs/plugin/localizedFormat'
import * as dayjs from 'dayjs'
dayjs.extend(LocalizedFormat)
dayjs.extend(relativeTime)
dayjs.extend(updateLocale)
dayjs.locale('is')

Error: "export 'extend' (imported as 'dayjs') was not found in 'dayjs'

So there already has been breaking changes, especially with usage on typescript so might as well just push these changes over since people are gonna have to update their projects

@TheThing I have the same issue. did you fixed yours? How?

I tried something like this:

import dayjs, { extend } from 'dayjs'

@vhscom It is still very early in the process and there may be potential bugs, and unit tests, plugins and locales have not yet been migrated.

@iamkun WDYT? We can release 2.0.0-alpha.0 by now?

Just released v1.10.2 to revert the esm module entry.

Let leave this breaking change to v2.0.0

More fun facts.

This doesn’t work in 1.10.1 in angular:

import dayjs from 'dayjs'
ERROR in app/app/app.module.ts:16:8 - error TS1259: Module '"D:/NFP/nfp/kisildalur/node_modules/dayjs/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag

16 import dayjs from 'dayjs'
          ~~~~~

  node_modules/dayjs/index.d.ts:3:1
    3 export = dayjs;
      ~~~~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.

However this will make it work

import * as inbetweener from 'dayjs'
let stupidtypescript:any = inbetweener
const dayjs = stupidtypescript.default
dayjs.extend(LocalizedFormat)
dayjs.extend(relativeTime)
dayjs.extend(updateLocale)
dayjs.locale('is')

lol

@bboydflo this is how you fix that stupid error xD

@alexsorokoletov THX, you can use the latest version of Day.js which has reverted this error change.