【发布时间】:2015-02-19 22:03:03
【问题描述】:
最近我发现了 Flux 架构,发现了this, React starter kit。良好的结构,但是,应用程序需要为浏览器编译,从 node.js 和 gulp。
我正在使用 reqwest 对服务器进行 ajax 调用,reqwest 需要 window ,这在 node.js 上不可用。当我从 ES 6 编译(使用gulp-render)到 ES 5.1 时,react render 会评估所有 require(..) 文件并因为未定义窗口而给我错误,我该如何避免这种情况?你有遇到过这样的事情吗?
events.js:72
throw er; // Unhandled 'error' event
^
ReferenceError: window is not defined
at E:\projects\micaimportanta\node_modules\reqwest\reqwest.js:13:13
at win (E:\projects\micaimportanta\node_modules\reqwest\reqwest.js:8:72)
at Object.<anonymous> (E:\projects\micaimportanta\node_modules\reqwest\reqwest.js:11:2)
at Module._compile (module.js:456:26)
at Module._extensions..js (module.js:474:10)
at reactTransform (E:\projects\micaimportanta\gulpfile.js:65:5)
at Object.Plugin.reactTransform (E:\projects\micaimportanta\node_modules\gulp-render\index.js:72:7)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
【问题讨论】:
标签: javascript node.js reactjs gulp reactjs-flux