需要上下文 `getStore`

Require context `getStore`

我在 Fluxible@0.4.10 遇到了一个小错误:

Warning: Failed Context Types: Required context `getStore` was not specified in `StoreConnector`. Check the render method of `NavIndexItemTheme`. /client-interface/node_modules/fluxible/addons/connectToStores.js:48 storeInstances[storeName] = this.context.getStore(store); ^ TypeError: undefined is not a function

其实我有这个:

components
          |_NavIndexItemTheme.jsx
...
templates
         |_tp1
              |_node_modules
              |             |_react
              |_Index.tpl.jsx

Index.tpl.jsx:

import React from "react";
import NavIndexItemTheme from "../../components/NavIndexItemTheme";

export default function(props) {
    return (
       <div className="index">
         <div className="wrapper flex fdc fas">
            <h1>Hello</h1>
            <NavIndexItemTheme />
          </div>
        </div>
    );
 }

如果我把node_modules文件夹删除到tp1目录下,是不会出错的。为什么这个目录会出错!!!

你不应该在一个项目中保留多个 node_modules 文件夹,这会给你的依赖解析带来歧义,从而导致混乱。看起来您的 Fluxible 模块的版本与项目根目录和 NavIndexItemTheme.

中使用的版本不同
  1. 至少使用 Fluxible 0.4.11,其中 context.getStore was added.
  2. 删除templates/tp1/node_modules
  3. 确保您的高阶组件(通常是 Application)包含在 fluxible/addons/provideContext() 函数中。