我很难让Browserify从ReactJS .NET MVC设置中使用演示页。
当使用.jsx文件在服务器上呈现时(不使用require()),所有操作都正常,但是当我使用Browserify包时,会出现以下错误:
'React.Exceptions.ReactInvalidComponentException‘类型的异常发生在React.dll中,但未在用户代码中处理。其他信息:无法找到名为“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包中访问,有简单的方法公开组件吗?
我正在命令行上运行我的浏览器化任务,所以任何有关这方面的建议都是有帮助的。
发布于 2015-04-10 18:22:02
您需要全面公开组件,以便可以从服务器端代码访问它。我还没有用Browserify尝试过,但是ReactJS.NET文档确实介绍了如何用Webpack:http://reactjs.net/guides/webpack.html来实现这一点。
https://stackoverflow.com/questions/29559951
复制相似问题