facebook / react

The library for web and native user interfaces.

Home Page:https://react.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug: How can I use react.lazy in "config.output.libraryTarget = 'umd'"

haoyinag opened this issue · comments

React version: "^16.14.0"

Steps To Reproduce

  1. create app with "create-react-app"
  2. install "react-app-rewired"
  3. set webpack config like
webpack: (config, env) => {  
    config.output.library = 'api-manage';
    config.output.libraryTarget = 'umd';
    config.output.umdNamedDefine = true;
    config.output.globalObject = 'this';
    config.output.publicPath = '//localhost:7777';
    // config.output.filename = 'api-manage.js';
    config.output.jsonpFunction = `webpackJsonp_api-manage`; 
    return config;
  }
  1. package.json
"micro": "react-app-rewired start"
  1. route
// run good
import Application from './ApplicationManage';
<Route
    path={`${requestedUrl}/application-manage`}
    component={ Application  }
  />

// run not correct
<Route
    path={`${requestedUrl}/application-manage`}
    component={lazy(() => import('./ApplicationManage'))}
  />
  1. run "yarn micro"
  2. the error messages
index.js:1517 The above error occurred in one of your React components:
    in Unknown (created by Context.Consumer)
    in Route (at CommonOperation/index.js:26)
    in Switch (at CommonOperation/index.js:23)
    in Suspense (at CommonOperation/index.js:22)
    in CommonOperation (created by Context.Consumer)
    in Route (at routes/index.js:48)
    in Switch (at routes/index.js:47)
    in Routes (at App.js:17)
    in div (created by Styled(MuiBox))
.......
commented

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!