'node.js not found (but installed) when compiling the default angular project in Visual Studio 2019
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?
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.
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.
Solution 1:[1]
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.
Solution 2:[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" <-----------------
}
...
Solution 3:[3]
add this tag in your "yourproject.csproj" file
<Target Name="OptimizeJs">
<Exec Command=".bin\node Scripts\r.js -o Scripts\build.js" />
</Target>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Jithin |
Solution 2 | murash |
Solution 3 | Azlin bin Muhamad Ali |