CycleJS makeHTTPDriver _add не является функцией

Только начинаю работать с CycleJs, и я столкнулся с этой ошибкой.

По сути, я запускаю изоморфный пример и добавляю драйвер HTTP так что я могу отправлять запросы

сервер.js

function wrapAppResultWithBoilerplate(appFn, context$, bundle$) {
  return function wrappedAppFn(sources) {
    const vdom$ = appFn(sources).DOM;
    const wrappedVDOM$ = xs
      .combine(vdom$, context$, bundle$.take(1))
      .map(wrapVTreeWithHTMLBoilerplate)
      .last();
    return Object.assign({}, sources, { DOM: wrappedVDOM$ });
  };
}
...
const context$ = xs.of({ route: req.url });
const wrappedAppFn = wrapAppResultWithBoilerplate(
  app,
  context$,
  clientBundle$
);
run(wrappedAppFn, {
  DOM: makeHTMLDriver(html => res.send(prependHTML5Doctype(html))),
  context: () => context$,
  PreventDefault: () => {},
  HTTP: makeHTTPDriver()
});
...

Трассировки стека

TypeError: (intermediate value)(intermediate value)._add is not a function
at MapFlatten._n (/Users/jethrolarson/github/isomorphic/node_modules/xstream/src/index.ts:954:35)
at Stream._n (/Users/jethrolarson/github/isomorphic/node_modules/xstream/src/index.ts:1193:22)
at CombineListener._n (/Users/jethrolarson/github/isomorphic/node_modules/xstream/src/index.ts:345:30)
at MemoryStream.Stream._n (/Users/jethrolarson/github/isomorphic/node_modules/xstream/src/index.ts:1193:22)
at MemoryStream._n (/Users/jethrolarson/github/isomorphic/node_modules/xstream/src/index.ts:2110:13)
at StartWith._start (/Users/jethrolarson/github/isomorphic/node_modules/xstream/src/index.ts:1112:14)
at MemoryStream._add (/Users/jethrolarson/github/isomorphic/node_modules/xstream/src/index.ts:2128:23)
at Combine._start (/Users/jethrolarson/github/isomorphic/node_modules/xstream/src/index.ts:396:14)
at Stream._add (/Users/jethrolarson/github/isomorphic/node_modules/xstream/src/index.ts:1250:23)
at MapFlatten._start (/Users/jethrolarson/github/isomorphic/node_modules/xstream/src/index.ts:928:20)
at Stream._add (/Users/jethrolarson/github/isomorphic/node_modules/xstream/src/index.ts:1250:23)
at Combine._start (/Users/jethrolarson/github/isomorphic/node_modules/xstream/src/index.ts:396:14)
at Stream._add (/Users/jethrolarson/github/isomorphic/node_modules/xstream/src/index.ts:1250:23)
at MapOp._start (/Users/jethrolarson/github/isomorphic/node_modules/xstream/src/index.ts:983:14)
at Stream._add (/Users/jethrolarson/github/isomorphic/node_modules/xstream/src/index.ts:1250:23)
at Last._start (/Users/jethrolarson/github/isomorphic/node_modules/xstream/src/index.ts:851:14)
at Stream._add (/Users/jethrolarson/github/isomorphic/node_modules/xstream/src/index.ts:1250:23)
at Stream.addListener (/Users/jethrolarson/github/isomorphic/node_modules/xstream/src/index.ts:1310:10)
at Stream.subscribe (/Users/jethrolarson/github/isomorphic/node_modules/xstream/src/index.ts:1330:10)
at /Users/jethrolarson/github/isomorphic/node_modules/@cycle/run/src/index.ts:143:54
at Array.map (native)
at replicateMany (/Users/jethrolarson/github/isomorphic/node_modules/@cycle/run/src/index.ts:143:6)
at run (/Users/jethrolarson/github/isomorphic/node_modules/@cycle/run/src/index.ts:230:32)
at run (/Users/jethrolarson/github/isomorphic/node_modules/@cycle/run/src/index.ts:272:10)
at /Users/jethrolarson/github/isomorphic/server.js:105:5
at Layer.handle [as handle_request] (/Users/jethrolarson/github/isomorphic/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/Users/jethrolarson/github/isomorphic/node_modules/express/lib/router/index.js:317:13)
at /Users/jethrolarson/github/isomorphic/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/Users/jethrolarson/github/isomorphic/node_modules/express/lib/router/index.js:335:12)
at next (/Users/jethrolarson/github/isomorphic/node_modules/express/lib/router/index.js:275:10)
at expressInit (/Users/jethrolarson/github/isomorphic/node_modules/express/lib/middleware/init.js:40:5)
at Layer.handle [as handle_request] (/Users/jethrolarson/github/isomorphic/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/Users/jethrolarson/github/isomorphic/node_modules/express/lib/router/index.js:317:13)
at /Users/jethrolarson/github/isomorphic/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/Users/jethrolarson/github/isomorphic/node_modules/express/lib/router/index.js:335:12)
at next (/Users/jethrolarson/github/isomorphic/node_modules/express/lib/router/index.js:275:10)
at query (/Users/jethrolarson/github/isomorphic/node_modules/express/lib/middleware/query.js:44:5)
at Layer.handle [as handle_request] (/Users/jethrolarson/github/isomorphic/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/Users/jethrolarson/github/isomorphic/node_modules/express/lib/router/index.js:317:13)
at /Users/jethrolarson/github/isomorphic/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/Users/jethrolarson/github/isomorphic/node_modules/express/lib/router/index.js:335:12)
at next (/Users/jethrolarson/github/isomorphic/node_modules/express/lib/router/index.js:275:10)
at Function.handle (/Users/jethrolarson/github/isomorphic/node_modules/express/lib/router/index.js:174:3)
at EventEmitter.handle (/Users/jethrolarson/github/isomorphic/node_modules/express/lib/application.js:174:10)
at Server.app (/Users/jethrolarson/github/isomorphic/node_modules/express/lib/express.js:38:9)
at emitTwo (events.js:106:13)
at Server.emit (events.js:191:7)
at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:543:12)
at HTTPParser.parserOnHeadersComplete (_http_common.js:105:23)

person Jethro Larson    schedule 29.04.2017    source источник


Ответы (2)


Можете ли вы опубликовать исходный код wrapAppFn?

Я бы предложил дважды проверить, что все исходящие приемники в wrapAppFn действительно являются потоками.

Вполне вероятно, что в какой-то момент что-то ожидает поток и получает значение другого типа.

person Widdershin    schedule 29.04.2017

Вероятно, поскольку вы, похоже, возвращаете sources в run(). Драйвер HTTP будет получать неправильный тип потока

Именно в таких проблемах TypeScript действительно хорош! Если вы используете такой редактор, как VSCode, вы получите информацию о типе даже при написании Javascript.

person Steve Lee    schedule 29.04.2017
comment
Я слышал о машинописном тексте. Я попытался заставить это работать, но не смог его скомпилировать, а ошибки машинописного текста были расплывчатыми и ни на что не ссылались в моем коде. - person Jethro Larson; 01.05.2017