项目用到了eslint-config-airbnb,但是安装这个包后启动会报错:
There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.
The react-scripts package provided by Create React App requires a dependency:
"eslint": "^7.11.0"
Don't try to install it manually: your package manager does it automatically.
However, a different version of eslint was detected higher up in the tree:
D:\ms\AutoDetectToolbox\ClientApp\node_modules\eslint (version: 6.8.0)
Manually installing incompatible versions is known to cause hard-to-debug issues.
If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.
按照官方的说法修复依赖树的话会删掉eslint,因为不能删所以该说法行不通。
折腾了一下午,在Stack Overflow找到了答案,原理就是卸载eslint,然后手动安装依赖版本。
比如,按照上面的报错,是要求^7.11.0版本的eslint, 执行以下命令:
npm uninstall eslint
npm i eslint@^7.11.0
这样就可以顺利运行啦~
参考:
reactjs - eslint error on deployment on local server of react web app - Stack Overflow