简体   繁体   English

结合Visual Studio 2015,gulp,browserify,React.js和JSX

[英]Combining Visual Studio 2015, gulp, browserify, React.js, and JSX

As a fairly Microsoft-centric and predominantly back-end programmer, tackling all of these (cool) new technologies all at once has proved pretty daunting. 作为一个相当以Microsoft为中心并且主要是后端程序员的公司,一次解决所有这些(很酷的)新技术已被证明是一项艰巨的任务。 I'm fairly pleased to say that I've got a lot of things wired together and that I feel as if i'm very close to breaking through one last hurdle to a point where i can finally begin to work and produce code efficiently in this brave new world, but there's a major obstacle I'm hung up right now. 我很高兴地说,我已经把很多东西连在一起了,我觉得我似乎已经很接近突破最后一个障碍了,我终于可以开始工作并高效地编写代码了。这个勇敢的新世界,但是我现在挂了一个主要障碍。 This is all new to me so i'll try to explain as i can: 这对我来说是全新的,所以我会尽力解释:

I'm using VS 2015 and building up a DNX ASP.NET 4.5 MVC 6 web application. 我正在使用VS 2015,并正在构建DNX ASP.NET 4.5 MVC 6 Web应用程序。 I've used NPM to install react, flux, and all manner of supporting modules. 我已经使用NPM安装了React,Flux和所有形式的支持模块。 I'm working on my first fully-functional JSX screen which is using the flux pattern to load data and I'm receiving callbacks from my store when the data is loaded from an API service. 我正在使用flux模式加载数据的第一个全功能JSX屏幕上,当从API服务加载数据时,我正在从商店接收回调。

I love being able to use the require('xxx') syntax to chain the dependencies together, so I've formed that habit and i'm using browserify & reactify from my gulp task to manage the dependencies, gather all of the input files, and convert my JSX files to JS at, er, gulp-time i guess. 我喜欢能够使用require('xxx')语法将依赖项链接在一起,因此我已经养成了这种习惯,并且我正在使用gulp任务中的browserify和reactify来管理依赖项,并收集所有输入文件,然后在大概的时间将我的JSX文件转换为JS。

The issue i'm running into now is one that I never expected: when I use require() in a JS file to include a JSX source file that defines one of my react components and then attempt to mount an instance of that component using ReactDOM.render and JSX syntax, i'm receiving the following error: 我现在遇到的问题是我从未料到的:当我在JS文件中使用require()来包含定义我的react组件之一的JSX源文件,然后尝试使用ReactDOM挂载该组件的实例时.render和JSX语法,我收到以下错误:

Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components). Check the render method of xxx Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components). Check the render method of xxx . Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components). Check the render method of xxx

Up to this point in the other areas of my app I've always included the react components thusly: 到目前为止,在我应用程序的其他区域中,我一直都这样包含了react组件:

ReactDOM.render(<MyComponent />, $("#reactTarget")[0]);

That has always worked. 这一直有效。 But now that I've bought in to the browserify world to chain these source files together, if i include the line 但是现在我已经进入了browserify领域,可以将这些源文件链接在一起(如果我将

var MyComponent = require('./MyComponent.jsx');

...and then proceed to try to include an instance of the component with: ...然后继续尝试将组件实例包含在:

ReactDOM.render(<MyComponent />, $("#reactTarget")[0]);

I receive the error above. 我收到上述错误。 Now given that all of this is new and somewhat fuzzy to me, i'm not 100% sure that it's the browserify aspect of this which is causing the issue, but it sure feels like it. 现在,鉴于所有这些对我来说都是新事物,并且有些模糊,我不是100%确信是造成此问题的原因是浏览器化方面,但确实有这种感觉。

I've also tried react.createClass , passing in the 'MyComponent' variable from the requires line, but no joy. 我也尝试了react.createClass ,从react.createClass传入'MyComponent'变量,但没有任何乐趣。

I have this mostly working but of course putting the data on the screen - in this case using react - is the whole point of the thing so, the fact that i now have a functional dispatcher, actions, stores and API calls is exciting but i can no longer simply compose my react components as i used to. 我主要是这样做的,但是当然要把数据显示在屏幕上(在这种情况下使用react)是整个问题的重点,因此,我现在具有功能分配器,操作,存储和API调用的事实令人兴奋,但是我不再像以前那样简单地组成我的反应组件。

what am i missing here? 我在这里想念什么? There must be a way to combine these techniques and technologies but i haven't been able to find an example that equates to this particular combination. 必须有一种将这些技术相结合的方法,但是我还没有找到一个等同于这种特定组合的示例。

Thanks in advance. 提前致谢。

I sometimes wonder what life would be like if I were a smarter animal. 有时我想知道如果我是一个聪明的动物,生活会怎样。 I've just spent an entire day - a weekend day, no less, chasing down phantom solutions and alternate configurations until I wanted to cry when in fact my issue was that I'd left off the 's' in module.exports at the end of my component definition. 我刚刚花了一整天-一个周末的日子,没少,追逐幻影解决方案和可选配置,直到我想哭的时候,其实我的问题是,我会离开的“s”在module.exports在我的组件定义的结尾。 That bloody 's' cost me years of my life, I suspect. 我怀疑,那血腥的事使我丧命了数年。 That's what I get for not copying/pasting when I'm toying with tings I barely understand. 这就是我在玩弄我几乎不了解的tings时不复制/粘贴的结果。 I guess I learned a lot in the process, maybe I'll get those hours back over time. 我想我在此过程中学到了很多东西,也许我会随着时间的流逝而恢复工作。

Thanks to anyone who made an effort here, or even pondered it at all. 感谢在这里付出努力,甚至根本不琢磨的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM