我正在为react-router-v4使用react-loadable,并且我想做服务器端渲染。当然,在服务器端我不需要延迟加载,所以我开始使用react-loadable,因为它告诉我在import-inspector babel插件的帮助下,它可以与服务器一起使用。
但不幸的是,我在服务器控制台require.ensure is not a function中遇到了错误,这导致客户端重新渲染,并且我正在失去服务器端渲染的所有好处。
在此之前,我一直在使用react-router-v3,并将getComponent与import配合使用,没有任何问题。
这是我的路由配置。
export default [
{
component: Root,
routes: [
{
path: '/',
component: Loadable({
loader: () => import('./Parent.jsx'),
loading: () => <div>Loading...</div>
}),
routes: [
{
path: '/',
exact: true,
component: Loadable({
loader: () => import('./Child.jsx'),
loading: () => <div>Loading...</div>
})
}
]
}
]
}
];这是我的.babelrc
{
presets : [["es2015", {modules: false}], "react", "stage-2", "stage-3"],
plugins: [
"transform-runtime",
"syntax-async-functions",
"dynamic-import-webpack"
],
env: {
node: {
plugins: [
["import-inspector", {
"serverSideRequirePath": true,
"webpackRequireWeakId": true,
}],
["babel-plugin-webpack-alias", {
"config": "webpack/server.js",
"findConfig": true
}]
]
}
}
}在客户端,它工作得很好,唯一的错误是标记校验和差异错误。这是怎么回事呢?
提前感谢!
发布于 2018-08-31 21:47:49
尝试将此添加到babel或babel加载器
"dynamic-import-node",
来自airbnb
https://stackoverflow.com/questions/45871443
复制相似问题