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
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.
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 CJSvar utcToZonedTime = require('date-fns-tz/esm') // Error here - not CJS
The solution would seem to be replacing the
package.json
linewith
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.