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

Cannot import isDayJs from the ESM output #1306

Closed
sybers opened this issue Jan 4, 2021 · 4 comments
Closed

Cannot import isDayJs from the ESM output #1306

sybers opened this issue Jan 4, 2021 · 4 comments

Comments

@sybers
Copy link

sybers commented Jan 4, 2021

Describe the bug
The following import doesn't work anymore.

import { isDayjs } from 'dayjs';

Before 1.10, the module field in package.json used to point to days.min.js which was not an ESM output. Now it is pointing to esm/index.js and the isDayjs function is not properly exported (it is only added to dayjs.isDayJs, which is later exported as the default export).

Same thing applies to locale, extend and unix functions.

Expected behavior
I'd like to be able to do:

import { isDayjs } from 'dayjs'

isDayjs(new Date());

instead of having to do:

import dayjs from 'dayjs';

dayjs.isDayjs(dayjs());

Information

  • Day.js Version: 1.10.1
  • OS: macOS@11.1
  • Bundler: Webpack@4.41.5
  • Browser: -
  • Time zone: -
@sybers sybers changed the title Cannot import isDayJs from the ESM version with a bundler Cannot import isDayJs from the ESM output Jan 4, 2021
@iamkun
Copy link
Owner

iamkun commented Jan 4, 2021

Sorry for the inconvenience, just wondering why a 'module' entry change could lead to such a huge change?

@sybers
Copy link
Author

sybers commented Jan 4, 2021

Oh I see you were already discussing the same issue on #1281 after opening this ticket.

As far as I understand, this is related to how UMD exposes the default export. But I am no expert in that domain 😅

A way to solve this would be to explicitly export the above functions in the source code.

@TheThing
Copy link

TheThing commented Jan 4, 2021

Yeah, it's weird how angular/babylon/whatever is repackaging the file cause node ecmascript modules doesn't care either way regardless of the version as I reproduced in my testing and provided identical output.

Feel free to use my shitty hotfix though that I posted at the end on that issue, lol

@iamkun
Copy link
Owner

iamkun commented Jan 5, 2021

let move this discussion to #1281

@iamkun iamkun closed this as completed Jan 5, 2021
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

No branches or pull requests

3 participants