Running npm command within Visual Studio Code

NpmVisual Studio-Code

Npm Problem Overview


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

Npm Solutions


Solution 1 - Npm

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.

Solution 2 - Npm

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.

  1. ctrl+Shift+p
  2. Type > Select Default Shell + Enter
  3. Select > Command Prompt ...cmd.exe
  4. Restart VS Code.

Solution 3 - Npm

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

Solution 4 - Npm

On Win10 I had to run VSCode as administrator to npm commands work.

Solution 5 - Npm

All you need to do is to add args to the integrated terminal within 'User Settings' window.

Follow this steps below to do that:

  1. List item
  2. Go to 'User Settings'
  3. Search for setting named - "terminal.integrated.shellArgs.windows"
  4. Edit this setting by copying it to the right side.
  5. Add the following arg value = "/k nodevars.bat", e.g. "terminal.integrated.shellArgs.windows": ["/k nodevars.bat"],
  6. 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.
  7. Open new Terminal.

Good luck

Solution 6 - Npm

I installed npm after Visual studio code, closed all visual studio instances and opened again and it started working.

Solution 7 - Npm

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.

Solution 8 - Npm

  1. Edit user setting file settings.json.
    • Settings > Search for settings.json > Edit in settings.json

    or

    • Run > type %APPDATA%\Code\User\settings.json
  2. Copy this code

    <code>{
    "terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe",
    "terminal.integrated.shellArgs.windows": ["/k nodevars.bat"]
    

    }

  3. Restart VS Code

Solution 9 - Npm

To install npm on VS Code:

  1. Click Ctrl+P
  2. Write ext install npm script runner
  3. 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
  4. Restart VS Code
  5. On the Integrated Terminal, Run 'npm install'

Solution 10 - Npm

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:

  1. Windows key and type "environment"
  2. Select "Edit the system environment variables"
  3. Click button labelled "Environment Variables..."
  4. In "System variables" section edit the "Path" variable
  5. 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.

Solution 11 - Npm

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.

Solution 12 - Npm

Try to install PowerShell extension provided by VS code.

PowerShell Extension

After install click on PowerShell and It will start new PowerShell Console where you can run all script

PowerShell Console

Solution 13 - Npm

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

Solution 14 - Npm

Well, anyone still ends up here, and couldn't resolve the problem, Here is how to fix it.

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

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

Solution 15 - Npm

There is an extension available, npm Script runner. I have not tried it myself, though.

Solution 16 - Npm

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.

Solution 17 - Npm

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. > > + [email protected] 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 > > [email protected] C:\Program Files\nodejs\node_modules\npm

Solution 18 - 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.

Solution 19 - Npm

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.

Solution 20 - Npm

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

Solution 21 - Npm

I restarted my machine, after checking the path in environment variable. it worked for me.

Solution 22 - Npm

You have to do the following 3 steps to fix your issues:

1.Download Node.js from here.

  1. Install it and then add the path C:\Program Files\nodejs to your System variables.

  2. Then restart your visual studio code editor.

Happy code

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiongarfbradazView Question on Stackoverflow
Solution 1 - NpmJaviereView Answer on Stackoverflow
Solution 2 - NpmIKriKanView Answer on Stackoverflow
Solution 3 - NpmAshish AhujaView Answer on Stackoverflow
Solution 4 - NpmDuFuSView Answer on Stackoverflow
Solution 5 - NpmbenshabatnoamView Answer on Stackoverflow
Solution 6 - NpmManish SadhwaniView Answer on Stackoverflow
Solution 7 - NpmMusabView Answer on Stackoverflow
Solution 8 - NpmGaurav ChavanView Answer on Stackoverflow
Solution 9 - NpmJNgugiView Answer on Stackoverflow
Solution 10 - NpmArckarophView Answer on Stackoverflow
Solution 11 - NpmNilay VishwakarmaView Answer on Stackoverflow
Solution 12 - Npmbhargav3vediView Answer on Stackoverflow
Solution 13 - Npmuser17965494View Answer on Stackoverflow
Solution 14 - Npmrs_puniaView Answer on Stackoverflow
Solution 15 - Npmuser3227106View Answer on Stackoverflow
Solution 16 - NpmTaalView Answer on Stackoverflow
Solution 17 - NpmPitView Answer on Stackoverflow
Solution 18 - NpmXinyi XiangView Answer on Stackoverflow
Solution 19 - NpmT.ToduaView Answer on Stackoverflow
Solution 20 - NpmSolomon SurajView Answer on Stackoverflow
Solution 21 - NpmSachin VishwakarmaView Answer on Stackoverflow
Solution 22 - NpmSoumyaranjan RoutView Answer on Stackoverflow