1
import React, { Component,lazy,Suspense} from 'react';
import LayoutComponent from './components/layout/Layout'
import BurgerBuilderContainer from './Containers/BurgerBuilder/BurgerBuilder'
import CheckoutContainer from './Containers/CheckOut/Checkout'
import { Route, Switch,withRouter } from 'react-router-dom'
 const OrdersContainer = lazy(()=> {
  return import('./Containers/Orders/Orders')
 })

Error Facing

render(){
return (
  <div>
    <Suspense fallback={<div>Loading...</div>}>
    <LayoutComponent>
      <Switch>
      <Route path="/Logout" component={LogoutContainer}></Route>
      <Route path="/Auth" component={AuthContainer}></Route>
        <Route path="/Orders" component={OrdersContainer}></Route>
        <Route path="/checkout" component={CheckoutContainer}></Route>
        <Route path="/" component={BurgerBuilderContainer}></Route>
      </Switch>
    </LayoutComponent>
    </Suspense>
  </div>
);
}

AsPer the error lazy loading is showing error on import, before using lazy loading application was working fine.

1 Answer 1

1

can you try with

const OrdersContainer= React.lazy(() => import('./Containers/Orders/Orders'));

if error continues try

const OrdersContainer= React.lazy(() => require('./Containers/Orders/Orders'));

if still continues

React.lazy(() => import("./Containers/Orders/Orders").then(x => x.default))

lastly

import @babel/plugin-syntax-dynamic-import

Sign up to request clarification or add additional context in comments.

6 Comments

thanks for the response. but i have tried this too but its not working same error
are you using create-react-app? if it is so which version of it?
"dependencies": { "axios": "^0.19.2", "prop-type": "0.0.1", "react": "^16.13.0", "react-dom": "^16.13.0", "react-redux": "^7.2.0", "react-router": "^5.1.2", "react-router-dom": "^5.1.2", "react-thunk": "^1.0.0", "redux": "^4.0.5", "redux-thunk": "^2.3.0" } Please Have a look
can you please try require instead of import? also make sure that lazy loading declaration is after all module imports
I believe that it is about the javascript version rather then react itself
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.