Skip to content

fix: 🐛 missing imports file extension for dayjs in ESM environments#933

Merged
punkbit merged 3 commits intomainfrom
fix/missing-extension-when-esm-modules-imported
Mar 18, 2026
Merged

fix: 🐛 missing imports file extension for dayjs in ESM environments#933
punkbit merged 3 commits intomainfrom
fix/missing-extension-when-esm-modules-imported

Conversation

@punkbit
Copy link
Collaborator

@punkbit punkbit commented Mar 18, 2026

Why?

The Dayjs package/library doesn't declare exports for bare imports, causing ESM environments to look up for a filename with a missing file extension, e.g. dayjs/plugin/advancedFormat instead of dayjs/plugin/advancedFormat.s.

Other packages work without .js because they define exports Day.js plugins break because the maintainers do not declare exports.

For this reason, consolidated dayjs imports and plugin configuration into src/utils/date.ts. Centralising these imports ensures consistent usage across components.

How?

  • Move dayjs exports to utils/date

Preview?

Nextra (ESM, previously erroring):

Screenshot 2026-03-18 at 16 44 15

Nextra server

Screenshot 2026-03-18 at 16 44 55

@changeset-bot
Copy link

changeset-bot bot commented Mar 18, 2026

🦋 Changeset detected

Latest commit: 4b8254b

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link

github-actions bot commented Mar 18, 2026

Claude finished @punkbit's task in 1m 2s —— View job


PR Review

Good fix for a real ESM compatibility pain point with dayjs plugins! The approach of centralising plugin imports and adding .js extensions is correct and clean. 🙌

✅ Core approach is correct — dayjs plugins don't declare exports in their package.json, so ESM module resolution fails without explicit .js extensions. Adding them + consolidating plugin setup in one place is the right pattern.


💡 Suggestions (non-blocking)

  • src/components/DatePicker/utils.ts: Still imports import dayjs from 'dayjs' directly (line 1) rather than from @/utils/date. It only uses base dayjs (no plugins), so it's not broken, but it's inconsistent with the goal of centralising dayjs imports. Worth updating for consistency. Fix this →

  • src/utils/date.test.ts: Same — imports dayjs directly. For tests this is less critical but worth aligning. Fix this →

  • No changeset added — if this fix affects consumers of the library in ESM environments, a patch changeset is warranted.


Overall the PR is in good shape and achieves its stated goal.

@github-actions
Copy link

github-actions bot commented Mar 18, 2026

Claude finished @punkbit's task in 55s —— View job


PR Review

Good fix for a real ESM pain point — centralising dayjs plugin setup and adding explicit .js extensions is exactly the right approach. The changeset is now included too. 🙌


✅ Core approach is correct — dayjs plugins don't declare exports in package.json, so ESM module resolution fails without explicit .js extensions. Consolidating plugin registration in one place (src/utils/date.ts) and exporting dayjs from there is the right pattern.


💡 Suggestions (non-blocking)

  • src/components/DatePicker/utils.ts:1 — Still imports dayjs directly from 'dayjs'. The plugin methods used here (.startOf(), .endOf(), .isSame()) are built-in so it won't break, but it's inconsistent with the goal of centralising dayjs imports. Since plugins are registered globally as a side effect, it works in practice only if @/utils/date is imported first somewhere in the tree. Fix this →

  • src/utils/date.test.ts:3 — Same direct dayjs import. Works because formatTimezone is imported from ./date (triggering plugin registration as a side effect), but worth aligning for consistency. Fix this →


Overall the PR achieves its stated goal cleanly. ✅

@workflow-authentication-public
Copy link
Contributor

📚 Storybook Preview Deployed

✅ Preview URL: https://click-gp3m7pbpi-clickhouse.vercel.app

Built from commit: def055f1bed42e5bdda109f6dee22ef81cf084cb

@punkbit punkbit merged commit 7d4f982 into main Mar 18, 2026
8 checks passed
@punkbit punkbit deleted the fix/missing-extension-when-esm-modules-imported branch March 18, 2026 16:49
punkbit added a commit that referenced this pull request Mar 18, 2026
…933)

* refactor: 💡 move days to date utils to help enforce extension for ESM consumer imports

* chore: 🤖 add note and TODO

* chore: 🤖 add changeset
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 this pull request may close these issues.

2 participants