V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
yocoso
V2EX  ›  React

umijs 项目启动时报错

  •  
  •   yocoso · 239 天前 · 1155 次点击
    这是一个创建于 239 天前的主题,其中的信息可能已经有所发展或是发生改变。

    别人做的 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 = {
    
    9 条回复    2023-09-07 15:26:09 +08:00
    dream4ever
        1
    dream4ever  
       238 天前
    看见 umi 我就头大,最近在尝试字节的 arco ,目前用下来感觉还不错(跑题了,哈哈
    totoro52
        2
    totoro52  
       238 天前
    检查一下你的 npm 和 node 版本
    karott7
        3
    karott7  
       238 天前
    试试切换一下 node 版本
    gofishing
        4
    gofishing  
       238 天前
    在项目 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
        5
    hesetiema  
       238 天前
    @dream4ever arco design? 看了下好像还不太成熟呀...,umi 其实做这种中后台项目够用了。
    yafoo
        6
    yafoo  
       238 天前 via Android
    换 node 版本试试
    dream4ever
        7
    dream4ever  
       238 天前
    @hesetiema umi 总感觉有些重,用起来也会有这样那样的小问题,可能和我不投缘吧,哈哈
    yocoso
        8
    yocoso  
    OP
       238 天前
    @gofishing 大神,就是这个问题!跪谢!但是为何对方没有问题?
    d119
        9
    d119  
       232 天前
    TMD 我就是被各种切来回版本搞服了,node 不服 npm ,npm 不服 nrm, eslint 不服 nrm ,react 不服 eslint ,卧艹
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2772 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 05:27 · PVG 13:27 · LAX 22:27 · JFK 01:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.