NPM start 返回错误,“项目依赖树可能有问题"; [英] NPM start returns error, "There might be a problem with the project dependency tree"
问题描述
我是编码新手,但对为什么无法正确设置 React 有疑问.上周我很挣扎,然后终于成功了.但现在我又遇到了同样的问题,但没有任何效果.
I'm new to coding and having issues with why I can no longer get React set up correctly. I struggled last week and then finally managed it. But now I have had the same issue again and nothing is working.
我有一个项目,我从 npx create-react-app
开始,然后当我进入项目时,我猜这个问题:
I have a project which I started with npx create-react-app
and then when I cd into the project I guess this issue:
项目依赖树可能有问题.这是可能不是 Create React App 中的错误,而是您需要修复的问题本地.
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.
Create React App 提供的 react-scripts 包需要一个依赖:
The react-scripts package provided by Create React App requires a dependency:
"webpack": "4.29.6"
"webpack": "4.29.6"
不要尝试手动安装:您的包管理器会这样做自动地.但是,检测到不同版本的 webpack在树的更高处:
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/aliceparker/node_modules/webpack(版本:4.33.0)
/Users/aliceparker/node_modules/webpack (version: 4.33.0)
已知手动安装不兼容的版本会导致难以调试的问题.
Manually installing incompatible versions is known to cause hard-to-debug issues.
如果您希望忽略此检查,请添加SKIP_PREFLIGHT_CHECK=true 到项目中的 .env 文件.那会永久禁用此消息,但您可能会遇到其他问题.
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:
- 删除项目文件夹中的 package-lock.json(不是 package.json!)和/或 yarn.lock.
- 删除项目文件夹中的 node_modules.
- 从项目文件夹的 package.json 文件中的依赖项和/或 devDependencies 中删除webpack".
- 运行 npm install 或 yarn,具体取决于您使用的包管理器.
在大多数情况下,这应该足以解决问题.如果这有没有帮助,您还可以尝试其他一些方法:
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:
如果您使用 npm,请安装 yarn (http://yarnpkg.com/) 并重复上面的步骤用它代替.这可能会有所帮助,因为 npm 存在包提升方面的已知问题,这些问题可能会在未来版本中得到解决.
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.
检查/Users/aliceparker/node_modules/webpack 是否在您的项目目录之外.例如,您可能不小心在主文件夹中安装了某些东西.
Check if /Users/aliceparker/node_modules/webpack is outside your project directory. For example, you might have accidentally installed something in your home folder.
尝试在您的项目文件夹中运行 npm ls webpack.这将告诉您哪些其他包(除了预期的 react-scripts)安装了 webpack.
Try running npm ls webpack in your project folder. This will tell you which other package (apart from the expected react-scripts) installed webpack.
如果没有其他帮助,请将 SKIP_PREFLIGHT_CHECK=true 添加到 .env 文件在你的项目中.这将永久禁用此预检以防万一你想继续.
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.
附言我们知道这条消息很长,但请阅读上面的步骤:-)我们希望它们对您有所帮助!
P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!
我已按照上述步骤操作.仍然得到问题.我还全局卸载了 webpack 并重新安装了它.
I've followed the steps above. Still get the issue. I've also uninstalled webpack globally and re-installed it.
这是我的 package.json 文件的样子:
Here is what my package.json file looks like:
`{
"name": "ravenous-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}`
任何人都可以指导我解决这个问题吗?(Ps.我只是尝试创建一个新项目,但遇到同样的问题...)
Can anyone kindly guide me through ways to solve this? (Ps. I tried just creating a new project, but get the same issue...)
推荐答案
在终端中,运行:
cd ~
那么:
ls
您应该会看到一个文件列表.如果 node_modules
包含在该列表中(看起来应该是这样),您希望删除该文件夹.您可以在终端中这样做:
You should see a list of files. If node_modules
is included in that list (as it appears it should be), you want to delete that folder. You can do so in the terminal like so:
rm -rf node_modules
但请记住:这不会将文件夹发送到垃圾箱.它将不可撤销地删除它.rm -rf
是一个强大的命令.如果这让您感到紧张,请输入 open .
代替.这将在 Finder 中打开您的主"(~
) 目录,您可以在那里以熟悉的、右键单击、发送到垃圾箱的方式删除 node_modules
.
But keep in mind: this will not send the folder to the trash. It will irrevocably delete it. rm -rf
is a powerful command. If that makes you nervous, type open .
instead. That will open your "home" (~
) directory in Finder, and you can delete node_modules
in the familiar, right-click, send-to-trash way there.
希望有帮助!
这篇关于NPM start 返回错误,“项目依赖树可能有问题";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!