【发布时间】:2021-11-11 10:17:05
【问题描述】:
在最近反应的应用程序上执行命令 npm start 时遇到问题。我对node.js没有太多经验,也没有在互联网上找到确切的问题,所以决定在这里问。
两天前我开始遇到一个问题,npm start 在我创建的任何 react 应用程序中都不起作用,今天早上我什至用 npx create-react-app test 创建了一个新的,在 VSCode 中打开项目文件夹并立即执行了 npm start 但遇到了同样的问题,所以我认为这不是我在其他应用程序中搞砸的事情。
我得到的错误是这样的
> sci-cal@0.1.0 start C:\Users\virgi\OneDrive\Documentos\VS_VSC\typescript_vsc\test
> 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.44.2"
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\virgi\node_modules\webpack (version: 5.52.1)
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 C:\Users\virgi\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! sci-cal@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the sci-cal@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\virgi\AppData\Roaming\npm-cache\_logs\2021-09-16T11_48_33_404Z-debug.log
我已经尝试了前四个步骤,但没有解决问题,并且 webpack 位于 node_modules 项目文件夹中。
我认为这可能是我使用的 react 版本没有更新,因此无法识别 webpack 5.52.1 版本的问题,但如前所述,我对 react 没有太多经验,也没有找到在互联网上修复了完全相同的问题,所以我决定在做任何其他事情之前先在这里询问,以防止问题可能变得更糟。
【问题讨论】:
-
你用的是什么 react 版本
-
@Hozeis,我的应用使用 React 版本 17.0.2,但 Cuong 已经教我如何解决这个问题。感谢您的关注。
标签: node.js reactjs react-native npm webpack