NPM missing in visual studio 2017 - node.js

I have Visual Studio 2017 and added support for Node.JS Development and ASP.Net Core. But when I go to Package Manager Console and write
npm
I am getting following error
The term 'npm' is not recognized as the name of a cmdlet
What could be a problem?
NPM should be fully integrated with VS
https://webtooling.visualstudio.com/package-managers/npm/

The default path for npm is:
C:\%ProgramFiles%\nodejs
You should have a npm.cmd there. The Windows PATH environment variable needs to point to that folder.
My advice is to reinstall nodejs from the source:
https://nodejs.org/en/download/
During Setup, making sure you choose Custom Setup and select "Add to PATH" and make sure it is set to "Will be installed on local hard drive".
(Of course, shut down all Visual Studio instances before doing the above.)

Related

Must I install NodeJS when it is already installed by the Visual Studio Installer?

Info
I am using Visual Studio 2019.
The Microsoft guides for creating SPA's requires you to install NodeJS from the official website, at least the guides I have perused so far.
When I installed Visual Studio I selected NodeJS development.
Visual studio installed NodeJS here: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VisualStudio\NodeJs
Question
My goal is to use NodeJS for development and NOT interfere with the operation of Visual Studio AND to only have one version of NodeJS installed AND to avoid installing NVM.
Must I install NodeJS again or should I use the version installed by Visual Studio?
It also raises the following concerns, which I don't expect to get answered here, but it would be nice to know:
If I install it again, will conflicts occur between the two versions?
If conflicts occur, how do I resolve them?
If I use the one installed by Visual Studio, can I update it at will, or does Visual Studio require a specific version of NodeJS?
See also
Multiple versions of node on windows
Install different versions of NodeJS
There was a question posted to the Microsoft Developer Community forums that also addresses this question. Quote:
Thank you for reporting this feedback. The NodeJS workload doesn’t install the Node Runtime and NPM on it’s own. The install you mentioned in the Visual Studio folder is used internally for Visual Studio operations. You would need to install the runtime you want to use separately, which would be picked up by NodeJS workload and corresponding apps.
In response to your question:
Must I install NodeJS again or should I use the version installed by Visual Studio?
Yes - so while it seems a whole separate copy of Node.js and npm is installed under C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VisualStudio\NodeJs when you install Visual Studio (with the Node.js workload), you are meant to install the regular version of Node.js and npm from https://nodejs.org/ and use that in your day-to-day development activities, which is what I've been doing (except with VS2022) and have not encountered any conflicts so far.
Edit: IF you do encounter conflicts with installed Node.js or npm versions, there is a way to resolve them, by changing the order of precedance of paths that VS uses. Go to 'Tools -> Options -> CTRL+E: "External Web Tools"' and you should see this:
Move the $(PATH) entry up or down depending on which version should take priority.
You can check if NodeJS is installed or not using the node -v and check if npm package manager is installed using npm -v. If you find that NodeJS is not installed, then download the NodeJS from here.

Visual Studio Installer is not installing node.js

In Visual Studio Installer, I selected the Node.js development option. It runs successfully. But, if I try to run cmd node -v. It tells me node does not exist.
I tried a few other things including uninstalling and reinstalling the Node.js development option in VS Installer. Plus installing the latest version of node from the website.
However, when I try to run the pre-packed Angular solution that comes with VS 2017 I have issues. The solution will not even start.
The best I have been able to do is install Node 6.10.3. Once I do that, the web site comes up. But, I get a JavaScript error in the vendor.js file. I am able to continue but I get this error when I try navigate to another menu item. Plus the Hot Module Replacement does not seem to be working. (It does not automatically recompile my TypeScript file if I made a change).
I think the key is getting the Node.js development option installed correctly since I am able to run the pre-packed Angular solution on another PC and the Hot Module Replacement works fine.
Please let me know if anyone has any ideas on how to resolve.
I had a similar, if not the same, issue. Check the Visual Studio installation directory (2017 Professional in this case) for Node:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\NodeJs
If the executable is there, add the directory to your PATH.

How can I set up gulp to run identically in Visual Studio 2017 and msbuild without having to change my build scripts?

I'm struggling to get set up with gulp in Visual Studio 2017. I'm not sure where I'm going wrong but there are a few things I'm confused about and I can't really find any online resources that are of any use.
The build system I'm using is CruiseControl.NET and I would like gulp to work with it.
This is what I've done so far:
Installed Visual Studio 2017 with .NET Core cross-platform development and Node.js development selected (amongst other options).
Created a new project
Added a gulpfile.js file to the project
Right-click on the file and choose Task Runner Explorer
In the Task Runner Explorer I get the error Failed to load. See output window (Ctl+Alt+O) for more information..
Then if I do the following:
Open the Node.js Interactive Window
Run the command .npm install --global gulp-cli
Close Visual Studio and open it back up again
In the Task Runner Explorer, I then get the message (No tasks found).
First off, is this the correct way to set up Gulp in Visual Studio 2017?
The reason I'm asking this is because I'm not sure why I need to prefix commands with a period character (ie .npm as opposed to npm).
I'm also not sure where gulp was installed because I can't find it in the path C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Web\External\node_modules.
Because of this I can't really set up CruiseControl.NET.
The way I'm handling this is to first use the Web Essentials 2017 extension. This installs the Bundler & Minifier tool, which then adds a bundleconfig.json file to your project. Right-click on this file, go to the Bundler & Minifier menu item and you will see an option in there to Convert To Gulp.
Selecting convert to gulp will create the necessary gulpfile.js and also install the npm packages required for using Gulp. Wait for all of the npm packages to install and you can then right click on gulpfile.js, select Task Runner Explorer and you should be ready to set up Gulp-based tasks. If you see gulpfile.js failed to load message, npm packages may still be installing (check the progress bar on the VS 2017 status bar). Hit the Refresh icon in Task Runner Explorer when all packages are installed and the error should vanish.
There's probably a more manual way to add Gulp support but I find this more automated method ensures all the tooling is wired up to work properly and I don't miss anything.
I gleaned all this information from the awesome Microsoft Docs site, specifically this page on Bundling & Minification. There's also a Using Gulp section in there that may provide additional details for your situation.
https://learn.microsoft.com/en-us/aspnet/core/client-side/bundling-and-minification
Microsoft have now added documentation on how to get gulp running:
https://learn.microsoft.com/en-us/aspnet/core/client-side/using-gulp
Make sure you update Visual Studio 2017 to the latest version as it now comes shipped with Node.js, NPM and Gulp (you don't need to pick "Node.js support" when installing Visual Studio for this to work).
Create an npm Configuration File (package.json) in your project folder and edit it to reference gulp:
{
"version": "1.0.0",
"name": "example",
"private": true,
"devDependencies": {
"gulp": "3.9.1"
},
"scripts": {
"gulp": "gulp"
}
}
In the project folder, create a Gulp Configuration File (gulpfile.js) to define the automated process.
Add the following to the post-build event command line for each project requiring gulp support:
cd $(ProjectDir)
call dotnet restore
npm run gulp
To run the tasks in Visual Studio 2017, open the Task Runner Explorer (View > Other Windows > Task Runner Explorer).
Then on the build server just install Node.js and ensure the path to node is added to the environmental path variable then when the build server builds the project gulp will run too!
I found the solution here. More information on that part of VS from Mads himself.
You have to force Visual Studio run with your Node.js version:
Go to Tools > Options in Visual Studio 2017
Go to Projects and Solutions > External Web Tools
Add the following path: C:\Program Files\nodejs

NPM error (System.ComponentModel.Win32Exception) in Visual Studio 2015

I need to get started coding an Angular 2 application at my workplace but I get the following error in VS:
====Executing command 'npm install'====
System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at Microsoft.VisualStudioTools.Project.ProcessOutput..ctor(Process process, Redirector redirector)
Error executing npm - unable to start the npm process
Error - Cannot load global packages.
I've followed Angular 2 VS 2015 QuickStart guide, located here:
https://angular.io/docs/ts/latest/cookbook/visual-studio-2015.html
Prerequisites are all installed:
VS 2015 with Update 3
nodeJS v.6.9.1
TypeScript v.2.0.6.0
This error shows up in the output when I open the project or try to do a 'restore packages'
Thanks.
It looks like you need other version of Node. You have maybe too new version of Node I guess. According to this thread: https://github.com/Microsoft/nodejstools/issues/476
you should downgrade and configure VS:
It looks like vs2015 does not work with the latest 5.0.0 Node. Replacing with 4.2.2 one solves this issue for me. To make Visual Stuido use the same Node and npm as cmd by changing some files including node.exe under following folder:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External
Look for this article also http://jameschambers.com/2015/09/upgrading-npm-in-visual-studio-2015/
I finally found out the reason.. nodeJS was installed with the x86 installer on a x64 computer. Installed nodeJS in 64 bit and it resolved my issue.
Hope this help anyone who has this error.

Node.js error (could not find) while creating Hybrid app in visual studio 2013

I have done fresh installation of Visual Studio 2013 - update 3 and have installed Visual studio 2013 MDA (Multi Device Application), and also have installed setup for Node js..
But when I create New Hybrid - Application project it shows me an error of "Node.js cannot be found"
Please help me..
You need to have NodeJS installed on your system.
Get the installer from this page: http://nodejs.org/download/
After installation you should also check if node command is usable the command line (cmd).
If it's not available you will need to manually add NodeJS to your path.

Resources