作者:zhenhuaYang | 来源:互联网 | 2022-12-02 17:51
我正在学习Lynda的学习反应课程.在第3章的第二个视频中,我面临一个问题.当我在Git Bash上键入npm start时,显示以下错误:
$ npm start
> bulletin-board@0.1.0 start C:\Users\John\Desktop\Ex_Files_Learning_Reactjs\Files\Ch03\03_02\start\bulletin-board
> react-scripts start
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:
"webpack": "4.19.1"
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:
C:\Users\John\node_modules\webpack (version: 2.5.1)
Manually installing incompatible versions is known to cause hard-to-debug issues.
If 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 C:\Users\John\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.
P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bulletin-board@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bulletin-board@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\John\AppData\Roaming\npm-cache\_logs\2018-10-09T09_26_01_403Z-debug.log
我遵循了第1步和第2步.但是我遇到了第3步的问题,我的项目文件夹中的package.json文件中没有依赖项和/或devDependencies的"webpack".
所以,我按照步骤4运行npm start.但我得到了同样大规模的错误.我该怎么做才能解决这个问题?
我的npm版本是5.6.0.
我被困住了,不能在没有修理的情况下继续前进.NPM对我非常恼火.我在Angular上做了一门课程,面对NPM的很多问题.现在,我正在做一个React课程,再一次,我受到了很多问题的影响.真的很烦人.
更新:
以下是package.json中的代码:
{
"name": "bulletin-board",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.5.2",
"react-dom": "^16.5.2",
"react-scripts": "^2.0.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
小智..
9
是的,我有同样的问题.我刚刚在C:\ Users\username的主目录中删除了node_modules.然后,npm开始,它工作.
1> 小智..:
是的,我有同样的问题.我刚刚在C:\ Users\username的主目录中删除了node_modules.然后,npm开始,它工作.
也适用于Mac