本文介绍了在 Visual Studio 2019 中编译默认 angular 项目时未找到(但已安装)node.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Visual Studio 2019 中创建了一个使用 .NET Core 3.0 的默认 Angular 项目.

I've created in Visual Studio 2019 a default Angular project with .NET Core 3.0.

当我构建项目并运行它时,出现以下错误:

When I build the project and run it, I obtain the following error:

error : Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE.

当网页启动时,我会收到异常,就像帖子末尾的图片一样.

And when the web page starts I obtain exceptions, like in the image at the end of the post.

我知道这个错误很容易修复:我只需要下载并安装 Node.js.但我想知道为什么我需要这样做,因为在 Visual Studio 安装程序中选择了 Node.js 选项,所以它应该已经安装了.您可以在我的 Visual Studio 安装程序窗口中看到它(抱歉,它是意大利语,但您仍然可以看到已经安装的 Node.js).

I know that the error is easy to fix: I need only to download and install Node.js. But I'd like to know why I need to do it, since in the Visual Studio Installer the Node.js option is selected, so it should be already installed. You can see it in my Visual Studio Installer window (sorry, it's in Italian, but you can see Node.js that's already installed anyway).

有没有办法解决问题并使用通过 Visual Studio 安装检索到的 node.js 而不是安装第二个?

Is there a way to fix the problem and use the node.js retrieved with Visual Studio installation instead of installing a second one?

我在 C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VisualStudio\NodeJs 中找到了 Visual Studio 安装的 node.exe 可执行文件.

I've found the node.exe executable installed by Visual Studio in C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VisualStudio\NodeJs.

我已经在 Options->Web Package Management 中添加了 External Web Tools 的路径,但错误仍然存​​在.

I've added the path to External Web Tools in Options->Web Package Management, but the error remains.

我在错误的地方设置了路径,还是有其他原因?

I'm setting the path in the wrong place, or there's something else?

我还注意到,在 .csproj 中,它使用 node 而不是 node.exe 引用节点可执行文件.我也改变了这个,但没有结果.

I've also noticed that in the .csproj, it refers to node executable with node instead of node.exe. I've also changed this but with no results.

推荐答案

打开 package.json 文件在依赖关系"中部分添加node-js依赖

Open the package.json fileIn the "dependencies" section add the node-js dependency

{
  "name": "Test.WebApp",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "bootstrap": "^4.3.1",
    "jquery": "3.3.1",
    "react": "^16.0.0",
    "react-dom": "^16.0.0",
    "react-router-bootstrap": "^0.24.4",
    "react-router-dom": "^4.2.2",
    "react-scripts": "^1.1.5",
    "reactstrap": "^6.3.0",
    "rimraf": "^2.6.2",
    "node-js": "^5.3.0" <-----------------
  }
...

这篇关于在 Visual Studio 2019 中编译默认 angular 项目时未找到(但已安装)node.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 16:20