Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 我可以使用require获得createSagaMiddleware吗?_Node.js_Redux Saga - Fatal编程技术网

Node.js 我可以使用require获得createSagaMiddleware吗?

Node.js 我可以使用require获得createSagaMiddleware吗?,node.js,redux-saga,Node.js,Redux Saga,我正在尝试在一个节点应用程序中使用run sagas,该应用程序将从命令行运行:node app.js 我无法使用导入,因此我正在尝试使用require获取createSagaMiddleware: const sagaMiddleware = createSagaMiddleware() 我得到这个错误: “TypeError:createSagaMiddleware不是函数” 传奇可以这样使用吗 const { createStore, combineReducers, applyMidd

我正在尝试在一个节点应用程序中使用run sagas,该应用程序将从命令行运行:
node app.js

我无法使用导入,因此我正在尝试使用require获取createSagaMiddleware:

const sagaMiddleware = createSagaMiddleware()
我得到这个错误:

“TypeError:createSagaMiddleware不是函数”

传奇可以这样使用吗

const { createStore, combineReducers, applyMiddleware } = require("redux");
const createSagaMiddleware  = require("redux-saga");
const {  take } = require("redux-saga/effects");

const sagaMiddleware = createSagaMiddleware();

const reducer = state => state;

const store = createStore(
    reducer,
    applyMiddleware(sagaMiddleware)
);

function* watcherSaga() {
    yield take("START");
    yield //do stuff
}

sagaMiddleware.run(watcherSaga)

store.dispatch({type: 'START'})
试试这个:

const createSagaMiddleware  = require("redux-saga").default;