0

刚刚开始使用 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)
4

2 回答 2

0

可能就像您似乎要返回sourcesrun() 一样。HTTP 驱动程序将获取错误类型的 Stream

这类问题是 TypeScript 真正令人震惊的地方!如果你使用像 VSCode 这样的编辑器,即使你正在编写 Javascript,你也会得到类型信息。

于 2017-04-29T14:57:29.167 回答
0

能发一下wrappedAppFn的源码吗?

我建议仔细检查一下 WrappedAppFn 中的所有传出接收器确实是 Streams。

似乎很可能在某些时候某些东西正在期待一个流并接收不同类型的值。

于 2017-04-29T02:06:05.707 回答