繁体   English   中英

依赖问题(ASP.NET Core + React.js)

[英]Dependency problem (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),但到目前为止似乎没有任何效果。

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

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

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

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

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM