Js-lingui: Locale lazy-loading breaks for me when running production build

Created on 29 Nov 2017  路  6Comments  路  Source: lingui/js-lingui

Hi, I could use some help with getting lazy-loading of locale files to work when running my application in production. I bootstrapped the project with create-react-app and it works in development but running the production build yields the following error, originating in the webpack function webpackAsyncContext

Uncaught (in promise) TypeError: undefined is not a function

but the previous step in the stack trace was the await import in my I18nLoader component's loadCatalog function which looks like this:

loadCatalog = async language => {
    // prettier-ignore
    const catalog = await import(
      /* webpackMode: "lazy", webpackChunkName: "i18n-[index]" */
      `../../locale/${language}/messages.js`);

    this.setState(state => ({
      catalogs: {
        ...state.catalogs,
        [language]: unpackCatalog(catalog),
      },
    }));
  };

I'm guessing there's some configuration I'm missing but I can't figure it out and would appreciate some help!

Most helpful comment

It's all good dude, js-lingui is amazing so thanks for doing what you do!

All 6 comments

Is it possible to share the bare minimum of your project? It would make debugging much easier. Otherwise I'll try what you said during weekend (bootstrap CRA, eject, setup lingui, add async loader).

I'm sorry, it's not possible for me to share the project I'm working on at the moment. I'll be working on it more on Tuesday if you can't find anything during the weekend.

I've not been able to figure out what's causing the error. Have you found anything that could cause something like this?

Disregard, it was me being a doofus! I had put babel-polyfill in devDependencies which means the await import broke when running in production.

Glad you figured it out! 馃憤 I'm sorry for lack of communication from my side, but I'm a bit overwhelmed last few weeks...

It's all good dude, js-lingui is amazing so thanks for doing what you do!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

felipeko picture felipeko  路  6Comments

MartinCerny-awin picture MartinCerny-awin  路  6Comments

zdzarsky picture zdzarsky  路  5Comments

benbender picture benbender  路  5Comments

SilentImp picture SilentImp  路  7Comments