11

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.

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).

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

Error in web page

node.js selected in Visual Studio Installer

EDIT:

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.

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

External Web Tools

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

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.

Jepessen
  • 11,744
  • 14
  • 82
  • 149
  • Is the path of your `node.js` install in the external tools search path? (Options | Projects and Solutions | Web Package Management.) – Richard Nov 30 '19 at 11:08
  • Where can I find the path? It's not shown in the installer. – Jepessen Nov 30 '19 at 11:18
  • When I install node.js it does show the path... which is `C:\Program Files\nodejs\node.exe`. – Richard Nov 30 '19 at 11:47
  • 1
    I've found node in `C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VisualStudio\NodeJs`. I've added the path where you've said but I've always the same error. – Jepessen Dec 01 '19 at 09:32
  • It is still saying you need node.js to *build* the project? Or just the runtime error? Please provide full details of how you are running node at build time (eg. starting with your `package.json` and details of how you are launching the build of the client side packages. – Richard Dec 01 '19 at 12:03
  • I've the same error that I've said in the post. When building the project it doesn't find node js even if I've added its path to external tools like I've said in the edit – Jepessen Dec 01 '19 at 15:32
  • 1. Location of `node.sh` is irrelevant (VS isn't running on a *nix OS): you need the location of `node.exe`. 2. Where are you seeing the build error? What else is logged before the error. And these rest of my last questions (VS won't directly call `node.exe` unless there is something to do that (eg. post build script or using a plugin to the task explorer). – Richard Dec 01 '19 at 16:35
  • I had a problem same as you and saw it's because of we have to restart the System when added the Node Js path in external tools and it will be fixed immediately. – Arash Yazdani Aug 08 '20 at 19:31
  • you need to configure the windows enviroment variables : https://stackoverflow.com/a/57193639/4718434 after that confirm node is configured correctly with this commands in cmd: `node -v` and `npm -v` . when you install nodejs (without visual studio), there is a checkbox for `add it to path`, that's why you should do this manually now. – yaya Aug 20 '20 at 06:53

4 Answers4

5
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.

I had the same issue, and it got fixed after I added the install path to Node JS, to the PATH Environment Variable.

I found the Visual studio installation of NodeJS in the following folder (using a simple search for Node.exe) C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VisualStudio\NodeJs

Copied the path, opened windows start menu, and searched for "Edit the system environment variables". Clicked the Environment Variables button, and under System variables found the Path variable.

Added the above copied NodeJS path to this variable.

I had to restart Visual Studio once, and I was able to build my solution.

Jithin
  • 51
  • 1
  • 3
  • I did similar, but found the C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Node.js script directly from the Node.js Windows installer, added this to the Path variable and my project also compiled. Thanks – Fandango68 Sep 02 '22 at 01:03
  • Worked perfectly. The visual studio path needs to be changed accordingly to what version of visual studio is installed, in my case I had to change 'Enterprise' with 'Professional' – Phate01 Jul 27 '23 at 16:51
0

According to Microsoft documentation: Ensure you have an environment variable called ASPNETCORE_ENVIRONMENT with value of Development. On Windows (in non-PowerShell prompts), run SET ASPNETCORE_ENVIRONMENT=Development. On Linux or macOS, run export ASPNETCORE_ENVIRONMENT=Development.

This solved my problem with ASP.NET Core with React project template.

-2

Open the package.json file In 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" <-----------------
  }
...
murash
  • 211
  • 3
  • 14
  • 1
    I can't seem to get a hit on this package in the version you mention. I only find [v.1.0.0](https://www.npmjs.com/package/node-js) from long time ago. What am I missing? – Konrad Viltersten Jan 11 '21 at 12:10
-2

add this tag in your "yourproject.csproj" file

<Target Name="OptimizeJs">
  <Exec Command=".bin\node Scripts\r.js -o Scripts\build.js" />
</Target>