反应-未检测到dom补丁React 16.6+功能可能不起作用

时间:2019-05-11 19:28:45

标签: reactjs gatsby

在Gatsby开发中,出现此错误。

React-Hot-Loader: react--dom patch is not detected. React 16.6+ features may not
work.

似乎是一个永无止境的错误,但是有没有办法从控制台中将其删除?

2 个答案:

答案 0 :(得分:1)

哦,天哪……issue中有一个解决方法

TL; DR

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'
    }
  }
}

答案 1 :(得分:1)

here所述,最好使用actions.setWebpackConfig,因为它会自动与默认配置合并:

exports.onCreateWebpackConfig = ({ stage, actions }) => {
  if (stage.startsWith("develop")) {
    actions.setWebpackConfig({
      resolve: {
        alias: {
          "react-dom": "@hot-loader/react-dom",
        },
      },
    })
  }
}