【问题标题】:adding react-big-calendar will cause Uncaught TypeError: Cannot read property 'matches' of null添加 react-big-calendar 将导致 Uncaught TypeError: Cannot read property 'matches' of null
【发布时间】:2017-05-30 08:07:42
【问题描述】:

复制回购

https://github.com/github0013/ror_rbc/commit/246f6e1839cdd6aababeeacb9301a80b040e453d

# git clone, then
bundle && npm install 
foreman start -f Procfile.dev # should start the server at http://localhost:3000/hello_world

问题

我正在使用
https://github.com/shakacode/react_on_rails
构建一个网络应用程序,但如果我尝试在 jsx 文件中import BigCalendar from 'react-big-calendar',它会在标题中给出错误。

我检查的东西

https://github.com/intljusticemission/react-big-calendar
这个库使用
https://github.com/react-bootstrap/dom-helpers

https://github.com/react-bootstrap/dom-helpers/blob/master/src/query/matches.js#L7
就我检查而言,这一行 document.body 为空。

为什么文档是空的?

我对 reactjs、webpack 等还是很陌生,所以我确定我缺少一些基本知识,但是如果有人能指出为什么缺少文档对象,请告诉我。

【问题讨论】:

    标签: ruby-on-rails reactjs webpack react-on-rails


    【解决方案1】:

    我找到了原因。

    https://github.com/github0013/ror_rbc/commit/3ef648d1ea3d647557b335ca6c5bdf7bd64c88b4

    javascript 文件链接在HEAD 标记内,即在BODY 标记之前。因此,由于尚未出现BODY 标签,因此在加载时,它缺少document.body

    javascript_include_tag 移动到BODY 标签的底部将其修复。

    【讨论】:

      【解决方案2】:

      我在我的应用程序中尝试了上述解决方案,然后又遇到了另一个错误。多个 Polly-fill 加载。 React On Rails 论坛说 JavaScript 文件通常加载在 HEAD 标记中。

      【讨论】:

      • 你克隆了我的 repo master 并得到了那个错误吗?还是您自己的应用程序?
      • 我尝试在我的应用中移动标签。错误消息:未捕获的错误:只允许一个 babel-polyfill 实例。该错误使我的引导 JS 无法在应用程序的其他页面上运行。
      • 您是否只移动了javascript_include_tag 行?无论哪种方式,您都在谈论“引导”库。我在这个问题中谈论“BigCalendar”。这可能有帮助吗? github.com/stylelint/stylelint/issues/1316
      猜你喜欢
      • 1970-01-01
      • 2018-06-30
      • 2018-07-22
      • 1970-01-01
      • 2018-01-23
      • 2019-08-08
      • 1970-01-01
      • 1970-01-01
      • 2021-07-29
      相关资源
      最近更新 更多