依赖关系问题(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:Usersxxxxnode_moduleswebpack (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:Usersxxxnode_moduleswebpack 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:Usersxxxnode_moduleswebpack (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:Usersxxxnode_moduleswebpack 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(,但到目前为止似乎都不起作用。

要解决此问题,除了dotnet 3.1 SDK之外,还需要节点包管理器(npm(。

您可以在此处下载并安装:https://nodejs.org/de/(我推荐Windows的巧克力(

安装后,您可以使用npm --version检查您的npm版本。如果没有答案,并且您在Windows上,则必须重新启动计算机一次。

如果成功安装了npm,则必须使用终端(或powershell(导航到项目文件夹,并运行命令npm install来重新安装所有依赖项。

如果您在安装所有模块时仍然存在问题,可以查看package.json文件,查看您使用哪个版本安装了哪些包,然后简单地更新或删除那里的包。在完成对package.json的编辑后,您必须再次运行npm install

这是关于如何更接近您的问题的一般帮助

我不久前遇到了这个问题。转到C:UsersUser,有一个名为node_modules的文件夹将其删除。不要运行npm install ...,只需转到VS(如果它打开,则关闭并重新启动(并创建一个新的React.Net核心项目。VS终端将下载并安装所有软件包。这解决了我的问题。

最新更新