rails react browserify TypeError: Object function has no method 'extend'

rails react browserify TypeError: Object function has no method 'extend'

我正在尝试使用 rails、React 和 browserify 制作网络应用程序。我一直以 this tutorial, and since I want server-side rendering, I've used this repo 作为起点,并遵循 README 文件中提到的教程。

虽然我认为我已经按照上述文章的建议做了一些事情,但我无法弄清楚如何解决以下错误:

TypeError: Object function ( w ) { if ( !w.document ) { throw new Error( "jQuery requires a window with a document" ); } return factory( w ); } has no method 'extend'

如果您想重现错误,请克隆 my repo,它是开源的并且在 github 上,然后转到功能分支 auth,安装 gems 和 npm 包并提起服务器:

$ cd path_to_project $ git checkout -b feature/auth $ bundle $ npm install $ bundle exec rails server

非常感谢任何帮助,因为我目前被困在这里。另外,我是新手,所以我不太知道在哪里寻找问题。

编辑:根据评论中的要求,我删除了堆栈跟踪以使问题更具可读性。如果您需要任何额外信息,请告诉我。

我正好在使用 j-toker CommonJS package which internally uses jQuery's ajax API. jQuery is incompatible with server side rendering since it needs a document element to load itself, and it only exists in the browser, not in the server. The solution is not yet at hand, but as J-Toker's author has indicated,他即将发布一个涵盖服务器端渲染案例的新库。

因此,对于遇到类似错误的任何人,请检查您是否正在使用 jquery 或任何其他反过来依赖于 jquery 的软件包,或者需要 document DOM 元素,并尝试使用服务器端呈现安全的替代方案。