umijs 项目启动时报错

250 天前
 yocoso

别人做的 web app ,他本地运行没问题, 给我源代码后,我进行 yarn install ,yarn build 之后再 yarn start ,浏览器打开时报错, 错误报于 redux ,请问这是什么问题?

Error: The slice reducer for key "session" returned undefined during initialization. If the state passed to the reducer is undefined, you must explicitly return the initial state. The initial state may not be undefined. If you don't want to set a value for this reducer, you can use null instead of undefined.

发不了包含全部 error stack 的截图,只能粘贴几个关键点了:基本就是 umi 和 dva 代码和 redux 之间的问题。

_DvaContainer.render
./src/.umi/plugin-dva/dva.ts:83
  80 |   render() {
  81 |     let app = getApp();
  82 |     app.router(() => this.props.children);
> 83 |     return app.start()();
  84 |   }
  85 | }
  86 | 
  initialValue
./src/.umi/umi.ts:30
  27 |         defaultTitle: ``,
  28 |       },
  29 |     });
> 30 |     return renderClient(opts);
  31 |   },
  32 |   args,
  33 | });
./src/.umi/umi.ts
./src/.umi/umi.ts:36
  33 | });
  34 | 
  35 | const clientRender = getClientRender();
> 36 | export default clientRender();
  37 | 
  38 | 
  39 |     window.g_umi = {
1186 次点击
所在节点    React
9 条回复
dream4ever
250 天前
看见 umi 我就头大,最近在尝试字节的 arco ,目前用下来感觉还不错(跑题了,哈哈
totoro52
250 天前
检查一下你的 npm 和 node 版本
karott7
250 天前
试试切换一下 node 版本
gofishing
250 天前
在项目 models 文件夹里找文件名是 session 的文件. 看它 state 字段是不是没定义.
models 文件夹可能不止一个, 文件名也能不是 session, 在文件里被 namespace 字段重写了.

总之, 就是找 dva 定义的 model, 看 state 字段是不是没定义.

参考 dva 和 umi 文档.
https://dvajs.com/guide/getting-started.html#%E5%AE%9A%E4%B9%89-model
https://v2.umijs.org/zh/guide/with-dva.html#model-%E6%B3%A8%E5%86%8Chttps://v2.umijs.org/zh/guide/with-dva.html#%E7%89%B9%E6%80%A7
hesetiema
250 天前
@dream4ever arco design? 看了下好像还不太成熟呀...,umi 其实做这种中后台项目够用了。
yafoo
250 天前
换 node 版本试试
dream4ever
250 天前
@hesetiema umi 总感觉有些重,用起来也会有这样那样的小问题,可能和我不投缘吧,哈哈
yocoso
250 天前
@gofishing 大神,就是这个问题!跪谢!但是为何对方没有问题?
d119
244 天前
TMD 我就是被各种切来回版本搞服了,node 不服 npm ,npm 不服 nrm, eslint 不服 nrm ,react 不服 eslint ,卧艹

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/970054

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX