react-- 未检测到 dom 补丁。React 16.6+ 功能可能无法使用

jam*_*son 2 reactjs gatsby

在 Gatsby 开发中,我收到此错误。

React-Hot-Loader: react--dom patch is not detected. React 16.6+ features may not
work.
Run Code Online (Sandbox Code Playgroud)

似乎是一个非破坏性错误,但有没有办法从控制台中删除它?

jam*_*son 6

哦,伙计......这个问题有一个解决方法

TL; 博士

npm install -D @hot-loader/react-dom

gatsby-node.js添加以下内容:

exports.onCreateWebpackConfig = ({ getConfig, stage }) => {
  const config = getConfig()
  if (stage.startsWith('develop') && config.resolve) {
    config.resolve.alias = {
      ...config.resolve.alias,
      'react-dom': '@hot-loader/react-dom'
    }
  }
}
Run Code Online (Sandbox Code Playgroud)