Description
Lodash inherently is not ESM compliant. This results in numerous warnings being thrown about potential optimization bailouts in Angular. For example, this is what I see when I run a production build that utilizes i18n:
▲ [WARNING] Module 'lodash/get' used by 'node_modules/i18n-js/dist/import/I18n.js' is not ESM
▲ [WARNING] Module 'lodash/has' used by 'node_modules/i18n-js/dist/import/I18n.js' is not ESM
▲ [WARNING] Module 'lodash/merge' used by 'node_modules/i18n-js/dist/import/I18n.js' is not ESM
▲ [WARNING] Module 'lodash/uniq' used by 'node_modules/i18n-js/dist/import/Locales.js' is not ESM
▲ [WARNING] Module 'lodash/camelCase' used by 'node_modules/i18n-js/dist/import/helpers/camelCaseKeys.js' is not ESM
▲ [WARNING] Module 'lodash/repeat' used by 'node_modules/i18n-js/dist/import/helpers/formatNumber.js' is not ESM
▲ [WARNING] Module 'lodash/sortBy' used by 'node_modules/i18n-js/dist/import/helpers/numberToHuman.js' is not ESM
▲ [WARNING] Module 'lodash/zipObject' used by 'node_modules/i18n-js/dist/import/helpers/numberToHuman.js' is not ESM
▲ [WARNING] Module 'lodash/range' used by 'node_modules/i18n-js/dist/import/helpers/timeAgoInWords.js' is not ESM
CommonJS or AMD dependencies can cause optimization bailouts.
For more information see: https://angular.dev/tools/cli/build#configuring-commonjs-dependencies
Obviously, this isn't ideal. I'm unsure if optimization bailouts are actually occurring, but regardless, this module should strive to be ESM compliant where it's easy to be via switching which flavor of lodash is being leveraged.
Describe the solution
Lodash has a number of build flavors available, one of them being lodash-es, which would allow the project to be ESM compliant out the gate with minimal changes required, my suggestion would be to update the package.json from:
"dependencies": {
...
"lodash": "*",
...
},
"devDependencies": {
...
"@types/lodash": "*",
...
},
to this:
"dependencies": {
...
"lodash-es": "*",
...
},
"devDependencies": {
...
"@types/lodash-es": "*",
...
},
As well as import statements from:
import camelCase from "lodash/camelCase"; to import camelCase from "lodash-es/camelCase"; this would allow the package to be considered ESM compliant from Angular's perspective, while maintaining functionality and dependency on lodash.
I am happy to submit a Pull-request if you agree with the approach. Should be relatively quick to whip up I'd imagine.
Description
Lodash inherently is not ESM compliant. This results in numerous warnings being thrown about potential optimization bailouts in Angular. For example, this is what I see when I run a production build that utilizes
i18n:Obviously, this isn't ideal. I'm unsure if optimization bailouts are actually occurring, but regardless, this module should strive to be ESM compliant where it's easy to be via switching which flavor of lodash is being leveraged.
Describe the solution
Lodash has a number of build flavors available, one of them being lodash-es, which would allow the project to be ESM compliant out the gate with minimal changes required, my suggestion would be to update the
package.jsonfrom:to this:
As well as import statements from:
import camelCase from "lodash/camelCase";toimport camelCase from "lodash-es/camelCase";this would allow the package to be considered ESM compliant from Angular's perspective, while maintaining functionality and dependency on lodash.I am happy to submit a Pull-request if you agree with the approach. Should be relatively quick to whip up I'd imagine.