c# - 依赖问题(ASP.NET Core + React.js)
问题描述
在使用 React.js 项目创建新的 ASP .NET Core (3.1) 应用程序后,我尝试运行它,但出现以下错误:
An unhandled exception occurred while processing the request.
AggregateException: One or more errors occurred. (One or more errors occurred. (The NPM script 'start' exited without indicating that the create-react-app server was listening for requests. The error output was:
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.42.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:
C:\Users\xxxx\node_modules\webpack (version: 5.25.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\xxx\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
))
System.Threading.Tasks.Task.ThrowIfExceptional(bool includeTaskCanceledExceptions)
InvalidOperationException: The NPM script 'start' exited without indicating that the create-react-app server was listening for requests. The error output was:
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.42.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:
C:\Users\xxx\node_modules\webpack (version: 5.25.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\xxx\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!
我已尝试按照此错误中包含的说明进行操作,但随后我遇到了一个带有 400 错误的空白页面。有谁知道如何解决它?我已经尝试了我在互联网上找到的所有东西(也手动安装了旧版本的 webpack),但到目前为止似乎没有任何效果。
解决方案
我不久前遇到了这个问题。转到C:\Users\User
那里有一个名为node_modules
删除它的文件夹。不要运行npm install ...
只是继续 VS(如果它打开则关闭并重新启动)并创建一个新的 React .Net 核心项目。VS 终端将下载并安装所有软件包。这解决了我的问题。
推荐阅读
- java - 你好我很难理解为什么它说构造函数未定义的java
- bash - 通过`$(...)`运行时bash`set -e`重置内部函数?
- python - 重新格式化数据框列
- javascript - 复选框向上文本
- django - 如何将 ForeignKey 到两个表之外的值?
- java - 找不到 com.example.roomwordssample.WordRoomDatabase 的实现。WordRoomDatabase_Impl 不存在
- java - 构建 Maven 项目不会创建 jar?
- vue.js - 实现 datetimepicker 来进行 vuetify
- python - 将字典的值拆分为单独的 panda 数据框列——使它们成为虚拟列
- python - Python中检查字符序数的不等式