Change Task Runner Explorer command - npm

In Visual Studio 2019 I have installed the extension call NPM Task Runner.
When I run a the build command the output is:
cmd.exe /c npm run build --color=always
How do I change that to:
npm run build --color=always
Because when I run the first one I get an error.
How can I fix the error or change the command.
P.S.: When I run the command like this npm run build --color=always in the console it works.

This fixed the problem for me.
Tools > Options > Projects and Solutions > Web Package Management >
External Web Tools
Move the $(PATH) entry to the 2nd position in the list by using the
up arrow button.
Post: Executes wrong version of nodejs

Related

Migrations and Testing CLI Commands Not Working in Visual Studio Code / VSCode Terminal

Running both migrations with "npm run migrate" and tests with "npm test" in the terminal in VSCode throws errors, yet if I run the same commands on the same project from the terminal on my mac, they run perfectly and as expected.
What is the reason for this?
Is there a way to configure my terminal in VSCode so that I can run migrations and testing through it or do I need to use the always use the terminal on my mac for migrations and testing?
your project probably contains some specific configuration for mac ios
the visual studio terminal is a powershell
you can test npm by running npm start on powershell
I need more information to be able to help, a print of the error is very useful...

Azure DevOps - npm invisible

I have a strange problem with a release pipeline in Azure DevOps.
I have two tasks:
1) Install packages
2) Run npm using the above packages
All seems to be easy so what I do is:
1) Command line task
npm install -g mkdirp 1.0.3
npm install -g newman
npm install -g newman-reporter-junitfull
2) PowerShell task
$(newman run $collection -e $environment --env-var "x=$(x)" -r junit --reporter-junit-export $resultFile)
This all worked fine until today. I tried a lot, but nothing works.
The error I have is:
newman : The term 'newman' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is correct and
try again.
Did anyone have a similar issue?
I ran above npm install scripts in a Command line task, and found only the first npm install command got executed. And my following powershell task to run newman command failed with above error message too. You can check the log of Command line task to see if it is the same issue.
If you want to report this issue, you can report a problem here.
The workaround i found is to run the npm install commands in a Powershell task too, do not use Command line task. Then the npm install commands will all get executed and the following powershell task can run successfully.
Or you can separate above three npm install commands into three Command line tasks to install them separately, which will make sure the newman library is installed.

Visual Studio Code (Windows) Not Detecting Global NPM Modules

I'm experiencing an issue where Visual Studio Code in Windows 10 is not able to detect globally installed NPM packages within the Integrated Terminal.
For example, if the windows command prompt I install #angular/cli via command npm install -g #angular/cli, within that command prompt I can execute #angular/cli commands such as ng --version without error. After that global npm module install, within Visual Studio Code, performing the same ng --version gives me the error:
The term 'ng' is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
I can however within the integrated terminal successfully perform commands such as npm -v and node -v.
I have the following items in my system environment variables
C:\Program Files\nodejs\
%AppData%\npm
Are there Visual Studio Code user or system environment variables I'm missing to allow detection of global npm modules?
Thank you for any help you can provide.
Visual Studio Code must be "Run as Administrator" for working Terminal Commands.
I was able to resolve the issue and use global npm commands in Visual Studio Code by modifying my system environment path variables to position %AppData%\npm before %ProgramFiles%\nodejs\ per npm troubleshooting tips
no need to do anything else just follow below steps -
right click on my computer (this pc).
go to properties.
click on advanced system setting.
click on environmental variable.
select path variable from system variable.
click on edit button.
add %AppData%\npm and %ProgramFiles%\nodejs\ at top of the list.
8 click on ok. ok. ok
restart your system.
after restart open visual studio code as run as administrative mode.
Enjoy...............!!!!!
Run Visual studio code as an administrator. Then type ng command. It should work
Reboot your computer , this worked for me
If you have entered the environment variable and it is still not recognized and if you don't want to reboot your computer because you have so many things running then just reboot your Visual Studio Or Visual Studio Code and then Open Terminal (ctrl + `) and run
npm install
Now it will work fine.
You can resolve the issue by opening the VS Code Terminal and type
npm install -g #angular/cli
This should resolve the issue.
Run powershell or cmd prompt in admin mode.
Check if npm and node commands work (if not, then check environment variables as others have mentioned).
Update node using npm [https://stackoverflow.com/questions/18412129/how-can-i-update-
npm-on-windows]
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install -g npm-windows-upgrade
npm-windows-upgrade
Run npm install -g #angular/cli
Run ng --version in Visual Studio Code to see if it's now working.
If you do not have access to Environmental variable (office machines).
You can try to run command like this:
npm run <your angular command>
it works as well, just need to add npm run before ng command
Example -> npm run ng g c shop/cart
I found that adding %AppData%\npm to your Path variable made it work for PowerShell and the Command Prompt, it still did not work for the integrated PowerShell in VS Code for me.
When I changed it from %AppData%\npm to the actual path C:\Users\<USER>\AppData\Roaming\npm where <USER> is your user directory, and reopened VS Code it started working.
Additionaly to all the good advice here, make sure that you have node.js installed on your machine.
To me the solution was adding the extensions for npm:

Intellij error gulp is not on your path

I'm running a project in intellij that uses gulp.
After running the debug I get this error.
| Error Error executing script RunApp: java.lang.RuntimeException: Problem executing execUiBuild.
standard out: 'Installing npm packages and running gulp.
gulp is not on your path. Make sure it is installed.
Anyone know how to fix this. I have gulp installed on my machine already.
In Intellij you can add Build/Run Configurations.
Depending on where you have Node installed and Gulp the paths will be different but here is where you can enter it for the project.
You can get to this screen by choosing "Run" -> "Edit Configurations"
If you haven't already setup a gulp task you can add one by choosing the + on the very top left of the window.
You can get the path to the installed version of node by doing the following command in a terminal:
which node
if you are using nvm it should return something like:
/Users/YOURUSERNAME/.nvm/v0.12.0/bin/node
Gulp should be in the /lib/node_modules/ folder of node that you have installed:
/Users/YOURUSERNAME/.nvm/v0.12.0/lib/node_modules/gulp
Those are the two paths that you need to get it up and running.

Running npm command within Visual Studio Code

Is there anyway of executing the npm command within Visual Studio Code (using f1 into >) on Windows(10) to install packages to my folder I'm working in?
I have npm installed and I keep having to install npm packages from cmd
Install
Ctrl+P, write ext install npm script runner
Restart VS Code
Use (two ways)
Ctrl+R Shift+R
Ctrl+P, write >npm, select run script, select the desired task
Update: Since version 1.3 Visual Studio Code has integrated terminal. To open it, use any of these methods:
Use the Ctrl+` keyboard shortcut.
Use the View | Toggle Integrated Terminal menu command.
From the Command Palette (Ctrl+Shift+P), use the View:Toggle Integrated Terminal command.
You can run npm commands directly in terminal (ctrl + `). Make sure that terminal has cmd.exe as the shell selected.
You can default cmd.exe as your shell by following these steps.
ctrl+Shift+p
Type > Select Default Shell + Enter
Select > Command Prompt ...cmd.exe
Restart VS Code.
There might be a chance that you have install node.js while your visual studio code was open.
Once node.js is install successfully, Simply close the VS Code and Start it again. It will work.
Thank you
On Win10 I had to run VSCode as administrator to npm commands work.
All you need to do is to add args to the integrated terminal within 'User Settings' window.
Follow this steps below to do that:
List item
Go to 'User Settings'
Search for setting named - "terminal.integrated.shellArgs.windows"
Edit this setting by copying it to the right side.
Add the following arg value = "/k nodevars.bat", e.g. "terminal.integrated.shellArgs.windows": ["/k nodevars.bat"],
Make sure that the setting named "terminal.integrated.shell.windows" is set to the value - "C:\Windows\system32\cmd.exe". If not then do that.
Open new Terminal.
Good luck
I installed npm after Visual studio code, closed all visual studio instances and opened again and it started working.
One reason might be if you install the node after starting the vs code,as vs code terminal integrated or external takes the path value which was at the time of starting the vs code and gives you error:
'node' is not recognized as an internal or external command,operable
program or batch file.
A simple restart of vs code will solve the issue.
Edit user setting file settings.json.
Settings > Search for settings.json > Edit in settings.json
or
Run > type %APPDATA%\Code\User\settings.json
Copy this code
{
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe",
"terminal.integrated.shellArgs.windows": ["/k nodevars.bat"]
}
Restart VS Code
To install npm on VS Code:
Click Ctrl+P
Write ext install npm script runner
On the results list look for npm 'npm commands for VS Code'. This npm manages commands. Click Install, then Reload VS Code to save changes
Restart VS Code
On the Integrated Terminal, Run 'npm install'
Same thing was happening to me after I installed Node.js. Node and npm was recognized in PowerShell and Command Prompt but not in VS Code. I fixed it by adding the Node.js install path to the system's environment PATH variable. The node.js install path on my system was:
C:\Program Files\nodejs
Where I find the node.exe that is needed. The user's PATH variable already had the Node.js install path but for some reason VS Code needs the Node.js install path in the system's PATH variables.
Windows 10 instructions:
Windows key and type "environment"
Select "Edit the system environment variables"
Click button labelled "Environment Variables..."
In "System variables" section edit the "Path" variable
Add Node.js install path to the list (C:\Program Files\nodejs)
The other answers were great but this is another way to fix it that worked for me without needing to install stuff, run as admin, or change the default settings.
VSCode User Setup is a new installer which installs VSCode and its dependencies in directories which don't require system-level / administrator permissions to modify. This is because New VSCode runs with user privileges. Your Nodejs installation added npm's path as System variable which VSCode cannot read.
Adding NPM path to Path variable in the User variable, you will be able to run NPM from the integrated command line.
Make sure you exit out of the existing terminal window. It will try to recover it and even though you may have closed out of VS Code you want to close the terminal window as well
Try to install PowerShell extension provided by VS code.
After install click on PowerShell and It will start new PowerShell Console where you can run all script
One from this two can help:
A) After you installed NodeJS, and restarted VScode, but still not getting npm to work, then idelete the opened terminal in VSCode with 'recycle' icon and try to create a new instance of terminal. From that moment and onwards, NPM should be working
B) If that doesn't help, then open up the prompt (Ctrl+P) and type >Terminal>Create terminal (with profile) and create 'cmd/powershell' based terminal. Afterwards, npm should be working.
Well, anyone still ends up here, and couldn't resolve the problem, Here is how to fix it.
Check the default terminal in VS Code (ctrl+ ~). It should be cmd and not Powershell.
If it is Powershell, go to settings > features > Terminal › Integrated ›
Default Profile: Windows. And select Command Prompt.
Or in search settings type 'default profile', and select Command Prompt.
Install VS Code extension - npm script runner (npm support for VS Code by Microsoft).
Click on extensions marketplace (ctrl + shift + x).
Type> npm script runner > install
After these steps, npm should be working from VS Code terminal.
There is an extension available, npm Script runner. I have not tried it myself, though.
As an alternative to some of the answers suggested above, if you have powershell installed, you can invoke that directly as your terminal. That is edit the corresponding setting.json value as follows:
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
I find this works well as the environment is correctly configured.
Open standard terminal ctrl+p and paste this command
npm i script-runner
Need to see this logs npm should be run outside of the node repl,
in your normal shell. (Press Control-D to exit.)
(To exit, press ^C again or type .exit)
C:\DW\Examples\Ang.Crud>npm i script-runner npm WARN saveError ENOENT:
no such file or directory, open 'C:\DW\Examples\Ang.Crud\package.json'
npm notice created a lockfile as package-lock.json. You should commit
this file. npm WARN enoent ENOENT: no such file or directory, open
'C:\DW\Examples\Ang.Crud\package.json' npm WARN Ang.Crud No
description npm WARN Ang.Crud No repository field. npm WARN Ang.Crud
No README data npm WARN Ang.Crud No license field.
script-runner#0.1.8 added 7 packages from 5 contributors and audited 7 packages in 2.955s found 0 vulnerabilities
Usage: npm
where is one of:
access, adduser, audit, bin, bugs, c, cache, ci, cit,
completion, config, create, ddp, dedupe, deprecate,
dist-tag, docs, doctor, edit, explore, get, help,
help-search, hook, i, init, install, install-test, it, link,
list, ln, login, logout, ls, outdated, owner, pack, ping,
prefix, profile, prune, publish, rb, rebuild, repo, restart,
root, run, run-script, s, se, search, set, shrinkwrap, star,
stars, start, stop, t, team, test, token, tst, un,
uninstall, unpublish, unstar, up, update, v, version, view,
whoami
npm -h quick help on npm -l display
full usage info npm help search for help on npm help
npm involved overview
Specify configs in the ini-formatted file:
C:\Users\fdc.npmrc or on the command line via: npm --key value Config info can be viewed via: npm help config
npm#6.4.1 C:\Program Files\nodejs\node_modules\npm
For me, this problem is fixed after installing the extension ES7 React/Redux/GraphQL/React-Native snippets. I am using windows 10 and the latest version of VS Code, and a little interpreter icon occurred on the lower right of the status bar.
Try this.
npm not works in Visual studio code
open vs code then Ctrl+P -> type - ext install npm script runner
you have to choose one and install it. once installed please close and open Visual studio code
and go to vs code terminal and type npm start and browser will start http://localhost:3000
Its working good. Thanks
I restarted my machine, after checking the path in environment variable. it worked for me.
In terminal run ->
npm install script-runner
You probably dont have your path variable set for npm on your machine. And typescript has nothing to do with this issue. VS Code is built on TypeScript for type checking when you're using JavaScript. But i'd suggest you to uninstall Node from your machine and re-install Node from here. Make sure you install the latest version of Node. Node comes with npm and it also sets the PATH_VARIABLE for terminal. In order to check if the path variable set or not , you can try this command node --version or npm --version.
Download Node.js from the link here
Install and then Then restart
You have to do the following 3 steps to fix your issues:
1.Download Node.js from here.
Install it and then add the path C:\Program Files\nodejs to your System variables.
Then restart your visual studio code editor.
Happy code