我正在尝试使用默认设置以及使用npx create-react-app为客户端创建的内部文件夹创建一个新的Rails应用程序。出于某种原因,一切都可以正常安装,但我不知道为什么Webpack版本号与我的默认版本不匹配。每当我将CD放入客户端文件夹并尝试启动时,我都会不断收到此错误。
为澄清起见,我的npx create-react-app客户端是在myapp文件夹中运行的...所以当前反应位于... / Users / JohnnyBrown / Desktop / myapp / client
我不了解我如何通过默认命令解决Webpack版本问题...
在终端中使用-v时,这里是我所有版本的版本号:
rails 6.0版, 纱线v-1.17.0, npm -v 6.9.0, 节点-v 10.13.0 webpack -v 4.34.0
我已经尝试了它提供的删除树上的内容的选项,但是这没有用..至少我什至无法使.env文件起作用,也许我没有放在正确的地方?任何见识将不胜感激。
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:
"webpack": "4.41.0"
Don't try to install it manually: your package manager does it automatically.
However, a different version of webpack was detected higher up in the tree:
/Users/JohnnyBrown/Desktop/myapp/node_modules/webpack (version: 4.41.2)
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.
To fix the dependency tree, try following the steps below in the exact order:
1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
2. Delete node_modules in your project folder.
3. Remove "webpack" from dependencies and/or devDependencies in the package.json file in your project folder.
4. Run npm install or yarn, depending on the package manager you use.
In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try:
5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
This may help because npm has known issues with package hoisting which may get resolved in future versions.
6. Check if /Users/JohnnyBrown/Desktop/myapp/node_modules/webpack is outside your project directory.
For example, you might have accidentally installed something in your home folder.
7. Try running npm ls webpack in your project folder.
This will tell you which other package (apart from the expected react-scripts) installed webpack.
If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in case you want to proceed anyway.```
答案 0 :(得分:0)
检查项目文件夹之外是否没有node_modules。必须删除它,然后再次运行“ npm start”