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

Feature request: Export import and require from 'date-fns-tz' #224

Closed
mcshaz opened this issue Jan 15, 2023 · 1 comment
Closed

Feature request: Export import and require from 'date-fns-tz' #224

mcshaz opened this issue Jan 15, 2023 · 1 comment

Comments

@mcshaz
Copy link
Contributor

mcshaz commented Jan 15, 2023

Having both the common JS and EcmaScript modules is great. A problem is that when consuming libraries (which are libraries themselves) wish to export both formats with a transpiling workflow, transpiled code will have been forced to selected either commonJS or ES modules. That is:

pre transpile: import { utcToZonedTime } from 'date-fns-tz/esm' // this will be the ESM code & doesn't need transpiling
post transpile to CJS var utcToZonedTime = require('date-fns-tz/esm') // Error here - not CJS

The solution would seem to be replacing the package.json line

"exports": {
    ".": "./index.js",

with

"exports": {
    ".": {
      "import": "./index.js",
      "require": "./esm/index.js"
    }

by leaving all the other exports, I do not believe this would be a breaking change - it will also require something like "engines":{"node":">=14.0.0"} - I am not sure of the lowest version of Node that began supported conditional exports, but it is around 14. Note Node 13 is no longer supported, so this should not be a huge change.

@marnusw
Copy link
Owner

marnusw commented Jan 30, 2023

Fixed via #212

@marnusw marnusw closed this as completed Jan 30, 2023
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

2 participants