question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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();

Code in App.jsx

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;

And in the HomePage.jsx. I just try translating one thing like that.

<h2>
            <Trans id="appName">Do whatever you want to do</Trans>
  </h2>

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
khaoptimist97commented, Oct 2, 2018

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

1reaction
khaoptimist97commented, Oct 2, 2018

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error in <Trans /> component with react-i18next - Stack Overflow
Uncaught Error: Trans(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return ...
Read more >
[Solved]-How to fix 'Invariant Violation - React Native
Coding example for the question How to fix 'Invariant Violation: requireNativeComponent: "RNGADBannerView" was not found in the UIManager'?-React Native.
Read more >
main.18b409e1.js.map - Google Git
node_modules/react-scripts/node_modules/promise/lib/rejection-tracking.js",". ... () {\n return args[argIndex++];\n }));\n error.name = 'Invariant Violation' ...
Read more >
Research Artefact: A Large-Scale Study of React-Related ...
Id PostTypeId AcceptedAnswerId OwnerUserId AnswerCount CommentCount Fa... 27279488 1 29040342 674474 3 5 0 29314839 1 29437736 2802074 2 2 3 30459180 1 30459458 745952 1...
Read more >
aws 502 bad gateway lambda Code Example - Code Grepper
For async tests and hooks, ensure "done()" is called; if returning a ... Invariant Violation: [React Intl] An `id` must be provided to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found