Ad

TypeError: React__WEBPACK_IMPORTED_MODULE_6___default.a.lazy Is Not A Function For [email protected]

- 1 answer

I'm trying to use lazy loading for my create-react-app with [email protected] and I did this :

import React, { Component } from 'react';
import { BrowserRouter } from 'react-router-dom';

const Header = React.lazy(() => import('./_header'));     

class SomeFile extends Component {

  render() {
    return (
      <BrowserRouter>
          <React.Fragment>
            <Header  />
          </React.Fragment>
      </BrowserRouter>
    );
  }
}

export default SomeFile;

Do you know why this error occurs ? is it because of my react version ? based on this everything seems fine!

Edit

What does this mean? based on reactjs.org :

Note:

React.lazy and Suspense is not yet available for server-side rendering. If you want to do code-splitting in a server rendered app, we recommend Loadable Components. It has a nice guide for bundle splitting with server-side rendering.

Ad

Answer

React.lazy is only available from v16.6.0 https://reactjs.org/blog/2018/10/23/react-v-16-6.html

Ad
source: stackoverflow.com
Ad