yocoso
V2EX  ›  React

umijs 项目启动时报错

  •  
  •   yocoso · Sep 1, 2023 · 2961 views
    This topic created in 1166 days ago, the information mentioned may be changed or developed.

    别人做的 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 replies  •  2023-09-07 15:26:09 +08:00
    dream4ever
    dream4ever
    Sep 1, 2023
    1
    看见 umi 我就头大,最近在尝试字节的 arco ,目前用下来感觉还不错(跑题了,哈哈
    MIUIOS
    MIUIOS
    Sep 1, 2023
    2
    检查一下你的 npm 和 node 版本
    karott7
    karott7
    Sep 1, 2023
    3
    试试切换一下 node 版本
    gofishing
    gofishing
    Sep 1, 2023
    4
    在项目 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
    hesetiema
    Sep 1, 2023
    5
    @dream4ever arco design? 看了下好像还不太成熟呀...,umi 其实做这种中后台项目够用了。
    yafoo
    yafoo
    Sep 1, 2023 via Android
    6
    换 node 版本试试
    dream4ever
    dream4ever
    Sep 1, 2023
    7
    @hesetiema umi 总感觉有些重,用起来也会有这样那样的小问题,可能和我不投缘吧,哈哈
    yocoso
    yocoso
    OP
    Sep 2, 2023
    8
    @gofishing 大神,就是这个问题!跪谢!但是为何对方没有问题?
    d119
    d119
    Sep 7, 2023
    9
    TMD 我就是被各种切来回版本搞服了,node 不服 npm ,npm 不服 nrm, eslint 不服 nrm ,react 不服 eslint ,卧艹
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2759 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 10:34 · PVG 18:34 · LAX 02:34 · JFK 05:34
    ♥ Do have faith in what you're doing.