React 15.x升级到16.x 运行环境报警告的解决方案

2,294 阅读1分钟

在git_carvip项目升级React到16.8.0版本,运行npm run devreact laidiantong的时候,会发现有一句警告提示,Warning: React version not specified in eslint-plugin-react settings. See github.com/yannickcr/e… 。如图:


虽然程序可以正常的运行,但是看到这句话还是有些不爽。看了内容可以定位是eslint验证react版本发生的警告,百度了一番,发现真的没有这个问题存在,后来在github上的eslint-plugin-react插件中发现很多人问了这个问题。大概就是在.eslinttrc.json中加入

"settings": {
     "react": {                  
          "version": "detect" // React version. "detect" automatically picks the version you have installed.                                               
                              // You can also use `16.0`, `16.3`, etc, if you want to override the detected value.                                              
                              // default to latest and warns if missing                                             
                              // It will default to "detect" in the future                 
     }
}
老外把version设置成999.999.999,测试了一下也好用。加上这段设置代码运行如下图: