date-fns: Missing buildLocalizeArrayFn module

I was trying to dynamically import locales from date-fns package and bumped into the following error:

Module not found: Can't resolve '../../../_lib/buildLocalizeArrayFn/index.js' in '/Users/ericreis/dev/vtex/test/node_modules/date-fns/locale/ar-DZ/_lib/localize'

Here is the code I’m using to perform the dynamic import:

const locale = 'en-GB'
import(`date-fns/locale/${locale}/index.js`).then(
  data => {
    console.log(data)
  })

I searched everywhere for this buildLocalizeArrayFnfolder, but I didn’t find it anywhere. Is it a bug? If not, could anyone point to me what I am doing wrong?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 5
  • Comments: 18 (14 by maintainers)

Commits related to this issue

Most upvoted comments

I’ve released a fix for this issue as v2.0.0-alpha.34: https://gist.github.com/kossnocorp/a307a464760b405bb78ef5020a4ab136#v200-alpha34

I did a work around for alpha 27 version by considering active locales

I created supportingLanguages.js with


const supportedLanguages = {
  af: async () => await import("date-fns/locale/af/index.js"),
  arSA: async () => await import("date-fns/locale/ar-SA/index.js"),
  bn: async () => await import("date-fns/locale/bn/index.js"),
  de: async () => await import("date-fns/locale/de/index.js"),
  el: async () => await import("date-fns/locale/el/index.js"),
  enCA: async () => await import("date-fns/locale/en-CA/index.js"),
  enGB: async () => await import("date-fns/locale/en-GB/index.js"),
  enUS: async () => await import("date-fns/locale/en-US/index.js"),
  eo: async () => await import("date-fns/locale/eo/index.js"),
  es: async () => await import("date-fns/locale/es/index.js"),
  et: async () => await import("date-fns/locale/et/index.js"),
  fr: async () => await import("date-fns/locale/fr/index.js"),
  gl: async () => await import("date-fns/locale/gl/index.js"),
  he: async () => await import("date-fns/locale/he/index.js"),
  hu: async () => await import("date-fns/locale/hu/index.js"),
  it: async () => await import("date-fns/locale/it/index.js"),
  ja: async () => await import("date-fns/locale/ja/index.js"),
  lt: async () => await import("date-fns/locale/lt/index.js"),
  nb: async () => await import("date-fns/locale/nb/index.js"),
  nl: async () => await import("date-fns/locale/nl/index.js"),
  pt: async () => await import("date-fns/locale/pt/index.js"),
  ptBR: async () => await import("date-fns/locale/pt-BR/index.js"),
  ru: async () => await import("date-fns/locale/ru/index.js"),
  sv: async () => await import("date-fns/locale/sv/index.js"),
  uk: async () => await import("date-fns/locale/uk/index.js"),
  vi: async () => await import("date-fns/locale/vi/index.js"),
  zhCN: async () => await import("date-fns/locale/zh-CN/index.js")
};


export default supportedLanguages;

and then where ever i wanted to import

 supportedLanguages[language]().then(localeFile => {
     //do something
    });

@kossnocorp perhaps then these locales should me moved to a separate location? Dynamic import is a powerful feature that right now is breaking due to outdated files in modules that won’t even be called.