Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can not use dynamic import #16

Open
chnliquan opened this issue Mar 11, 2019 · 0 comments
Open

can not use dynamic import #16

chnliquan opened this issue Mar 11, 2019 · 0 comments

Comments

@chnliquan
Copy link

chnliquan commented Mar 11, 2019

when i use dynamic import in react router as follows, the following problem has occurred
the error only occurred in development mode, not in production mode

import React from 'react'
import { Route, Redirect, withRouter, } from 'react-router-dom'
import Loadable from 'react-loadable'

import CircularProgress from '@material-ui/core/CircularProgress'
// right

// import TopicList from 'views/topic-list'
// import TopicDetail from 'views/topic-detail'
// import TopicCreate from 'views/topic-create'
// import UserLogin from 'views/user/login'
// import UserInfo from 'views/user/info'

// wrong
const TopicList = Loadable({
  loader: () => import('views/topic-list'),
  loading() {
    return <CircularProgress />
  },
})

const TopicDetail = Loadable({
  loader: () => import('views/topic-detail'),
  loading() {
    return <CircularProgress />
  },
})

const TopicCreate = Loadable({
  loader: () => import('views/topic-create'),
  loading() {
    return <CircularProgress />
  },
})

const UserLogin = Loadable({
  loader: () => import('views/user/login'),
  loading() {
    return <CircularProgress />
  },
})

const UserInfo = Loadable({
  loader: () => import('views/user/info'),
  loading() {
    return <CircularProgress />
  },
})


export default () => [
  <Route exact render={() => <Redirect to="/list" />} path="/" key="home" />,
  <Route component={TopicList} path="/list" key="list" />,
  <Route component={TopicDetail} path="/detail/:id" key="detail" />,
]
{ Error: Cannot find module './0.server-entry.js'
    at Function.Module._resolveFilename (module.js:548:15)
    at Function.Module._load (module.js:475:25)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Function.requireEnsure [as e] (server-entry.js:46:25)
    at loader (webpack:///./client/router/index.jsx?:69:60)
    at load (/Users/ender/learning/github/react-cnode/node_modules/react-loadable/lib/index.js:28:17)
    at init (/Users/ender/learning/github/react-cnode/node_modules/react-loadable/lib/index.js:121:13)
    at new LoadableComponent (/Users/ender/learning/github/react-cnode/node_modules/react-loadable/lib/index.js:150:7)
    at /Users/ender/learning/github/react-cnode/node_modules/react-tree-walker/dist/react-tree-walker.js:174:30 code: 'MODULE_NOT_FOUND' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant