Running ReactJS.NET with browserify



我正在努力让Browserify使用ReactJS。NET MVC设置。

当使用.jsx文件(不使用require())在服务器上渲染时,一切都正常,但当我使用Browserify捆绑包时,我会得到一个错误:

React类型的异常。例外情况。React.dll中出现ReactInvalidComponentException,但未在用户代码中进行处理。其他信息:找不到名为"CommentBox"的组件。您是否忘记将其添加到App_Start\ReactConfig.cs?

这是我的观点:

@Html.React("CommentBox", new
{
initialData = Model
})
<script src="http://fb.me/react-0.12.2.js"></script>
<script src="src/to/bundle.js"></script>
@Html.ReactInitJavaScript()

ReactInitJavascript()编译为:

<script>React.render(React.createElement(CommentBox, {"initialData":[{"Author":"Daniel Lo Nigro","Text":"Hello ReactJS.NET World!"},{"Author":"Pete Hunt","Text":"This is one comment"}]}), document.getElementById("react1"));

我假设CommentBox没有定义,因为它不能从Browserify捆绑包访问,有没有一种简单的方法来公开组件?

我正在命令行上运行我的浏览任务,所以任何建议都会很有帮助。

您需要全局公开组件,以便可以从服务器端代码访问它。我还没有在Browserify上尝试过,但在ReactJS上。NET文档确实介绍了如何使用Webpack做到这一点:http://reactjs.net/guides/webpack.html

最新更新