Open nskazki opened 1 year ago
Other ESM files importing CJS functions:
I have the same problem. Getting CommonJS or AMD dependencies can cause optimization bailouts.
in Angular.
@nskazki The problem is not so much the syntax for importing ESM, but the fact that the date-fns
ESM section of the project doesn't specify type: module
. That means when you try to build date-fns-tz
importing ESM files files from the default type: commonjs
project into a type: module
project you also have problems.
Perhaps I'm wrong and I missed something. I can go back and take another look when I have time. But I don't think it's as simple to solve this as you suggest here.
If you have the time to see whether you can import ESM from date-fns
and get this library to build please create a PR; I'm not sure I'll get round to it in the too near future.
Well, it would have solved the problem for me with my Webpack config.
I won't argue with you. Seeing as this is a big deal for you at the moment please submit the changes in a PR. Please just ensure you can run the build and package commands successfully beforehand. If that works, you will have solved a painpoint for many!
Okay, will do. Thanks for being so open to suggestions!
@marnusw, I haven't succeeded with https://github.com/marnusw/date-fns-tz/pull/204.
date-fns-tz
that imports ES-only modules from date-fns
only works with Webpack because, unlike NodeJS, Webpack recognizes the module
field in package.json
. I don't know how to make the patched date-fns-tz
work with NodeJS and Webpack without patching date-fns
.
Thank you for trying @nskazki. That was my unfortunate finding as well. You can help by applying some pressure over at date-fns
. 😄
https://github.com/marnusw/date-fns-tz/blob/4ced7b8b0a5aad5b08fc3a44476242c82bc3272d/src/format/index.js#L1
For
dateFnsFormat
to be imported as EMS, not CJS, it should have been written like so