【问题标题】:Dependency problem (ASP.NET Core + React.js)依赖问题(ASP.NET Core + React.js)
【发布时间】:2021-03-17 07:57:29
【问题描述】:

使用 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# asp.net .net asp.net-mvc asp.net-core


【解决方案1】:

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

您可以在这里下载并安装它:https://nodejs.org/de/ (我会推荐 Chocolatey for Windows)

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

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

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

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多