Js-lingui: Unhandled Rejection (Invariant Violation): Trans(...): Nothing was returned from render

Created on 28 Sep 2018  路  10Comments  路  Source: lingui/js-lingui

Solution

  • If you use create-react-app 1.x, update to 2.x.
  • If you use custom Babel config, add macros plugin

Original issue

Hi all, I have a problem when try to follow the steps in documentation (Tutorial for React).

The error: Trans(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.

My project has App component separately. It doesn like the example from doc. I got the project done after finishing React course in Udemy and I want to translate this app.
I confused to determine the place of I18nProvider should be. Would I put it in index.js or App.jsx.
Im a beginner with React, so I will appreciate in advance with any help from you guys.

index.js:

const store = configureStore();
const rootEl = document.getElementById('root');
let render = () => {
  ReactDOM.render(
    <Provider store={store}>
      <I18nProvider language="vi" catalogs={{ vi: catalogVi }}>
        <BrowserRouter>
          <ScrollToTop>
            <ReduxToastr position="bottom-right" transitionIn="fadeIn" transitionOut="fadeOut" />
            <App />
          </ScrollToTop>
        </BrowserRouter>
      </I18nProvider>
    </Provider>,
    rootEl
  );
};
if (module.hot) {
  module.hot.accept('./app/layout/App', () => {
    setTimeout(render);
  });
}
store.firebaseAuthIsReady.then(() => {
  render();
});

registerServiceWorker();



md5-5506df47aeead25a2f9be497e1cbc361



class App extends Component {
  render() {
    return (
      <div>
        <AsyncModalManager />
        <Switch>
                  // This is the component I want to translate
                 <Route exact path="/" component={HomePage} />_ 
        </Switch>
        <Route
          path="/(.+)"
          render={() => (
            <div>
              <AsyncNavBar />
              <Container className="main">
                <Switch>
                  <Route path="/events" component={AsyncEventDashboard} />
                  <Route path="/event/:id" component={AsyncEventDetailedPage} />
                  <Route path="/manage/:id" component={UserIsAuthenticated(AsyncEventForm)} />
                  <Route path="/people" component={UserIsAuthenticated(AsyncPeopleDashboard)} />
                  <Route path="/profile/:id" component={UserIsAuthenticated(AsyncUserDetailedPage)} />
                  <Route path="/settings" component={UserIsAuthenticated(AsyncSettingsDashboard)} />
                  <Route path="/createEvent" component={UserIsAuthenticated(AsyncEventForm)} />
                  <Route path="/error" component={AsyncNotFound} />
                  {/* Every wrong path return to Not found component */}
                  <Route component={AsyncNotFound} />
                </Switch>
              </Container>
            </div>
          )}
        />
      </div>
    );
  }
}
export default App;



md5-1c9813f3d6c234f70feaae5c64c1d452





md5-83b3e736521c6961d4d880079e157671


After extract and compile, I could see the messages.js in catalogs. But when running in development mode, it throws this kind of error. I knew that I have some mistakes at some points. But I dont really understand deeply how it works. Please give me any suggestion. Thanks

馃尡 create-react-app

All 10 comments

I'm stuck in the same problem.

Could you please create a repository with minimal example to reproduce this bug? I've just tried it with react-router-dom and creat-react-app and it works for me.

Hi @tricoder42
Would it be possible with project using webpack code splitting currently?

@khaoptimist97 Do you use Create React App 1.x? @dhrubesh has similar issue and it's cased by this. If so, please upgrade to 2.x if you can (should be easy). That's the easiest way to use Trans macro.

@tricoder42 OMG it's magic. I've upgraded to 2.x and eventually it works. Thank you for your support.

@dhrubesh Check it out to upgrade the latest version bro: https://reactjs.org/blog/2018/10/01/create-react-app-v2.html

@tricoder42
Do you happen to know what exactly in Create React App 2.x is solving the issue? I've ejected my application and I've also encountered the same problem.

It's hard to tell. Could you please publish your repository or at least a minimal example to debug it?

Actually, my bad, sorry. I forgot to add the "macros" plugin to .babelrc - now it seems to be working!

Great! I'll add this solution to troubleshooting. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

landsman picture landsman  路  4Comments

mojtabast picture mojtabast  路  4Comments

ludwigbacklund picture ludwigbacklund  路  6Comments

MartinCerny-awin picture MartinCerny-awin  路  6Comments

gitschwifty picture gitschwifty  路  3Comments