7

I'm working on a React/Webpack/Globalize app. In development mode things are ok-ish (though Globalize insists on compiling all locales instead of the one i have selected but that's another question for another day).
However, when I'm setting production: true in my webpack config, I'm getting the following error when running npm run build

> webpack --config webpack.prod.config.js

/opt/app/ui/node_modules/globalize-webpack-plugin/GlobalizeCompilerHelper.js:72
      throw e;
            ^
Error: No formatters or parsers has been provided

I was under the impression the globalize webpack plugin is meant to handle precompilation. Any idea why I'm seeing this error? When I'm setting production: false things compile fine.

My plugin setup is:

new GlobalizePlugin({
            production: true,
            developmentLocale: "en",
            supportedLocales: [ "en"],
            output: "i18n/[locale].[hash].js" 
        }),

When a file changes and webpack dev server rebuilds, I'm getting a LOT of these messages indicating recomplication of locales I am not using:

[461] ./~/cldr-data/main/es-PY/dateFields.json 15 kB {0} [optional]
[462] ./~/cldr-data/main/es-SV/dateFields.json 15 kB {0} [optional]
[463] ./~/cldr-data/main/es-US/dateFields.json 15 kB {0} [optional]
[464] ./~/cldr-data/main/es-UY/dateFields.json 15 kB {0} [optional]
[465] ./~/cldr-data/main/es-VE/dateFields.json 15 kB {0} [optional]
[466] ./~/cldr-data/main/es/dateFields.json 15 kB {0} [optional]

Nothing I try seems to get passed that problem.
Thanks

Harel
  • 1,989
  • 3
  • 26
  • 44
  • Please, could you provide a link with a reduced example that I can use to reproduce the problem you are facing (e.g., by using http://gist.github.com)? – Rafael Xavier Dec 27 '15 at 22:28
  • Sorry, I doubt I'll have the time as I've resolved this for now (see my answer below). The quick way to replicate it is simply adding the GlobalizePlugin config to webpack's config file, without the messages key, and setting production to true. Then `npm run build` should fail with this error. – Harel Dec 27 '15 at 23:24
  • 1
    I'm happy that you found a workaround, but it isn't correct. The `messages` key is optional (differently than your answer below). If you or anyone else are interested on investigating this, just let me know. I can't reproduce the failure you get, so unfortunately I'm unable to suggest anything for you. Thanks – Rafael Xavier Dec 29 '15 at 17:56
  • 1
    Update. The error happens when no Globalize functions are used in the source code. This should be fixed by https://github.com/rxaviers/globalize-webpack-plugin/issues/10. Thanks for filing the issue. – Rafael Xavier Dec 29 '15 at 18:13

1 Answers1

2

As it stands, the messages key is not 'optional', but actually required. More than that, somewhere you need to 'prime' (for lack of a better word) the message formatter by calling Globalize.formatMessage("somekey") (where somekey exists in your lang file). All this is required when production is set to true.

As well, if you do set production to true, the output path must match an existing path in your source tree. If for example your code builds into /assets, the output path should be assets/i18n/[locale].[hash].js. Otherwise the i18n directory will not be created on build.

All this is derived from a discussion in the github repo:

https://github.com/rxaviers/globalize-webpack-plugin/issues/10

Harel
  • 1,989
  • 3
  • 26
  • 44