Override default npm install from InitelliJ IDEA - npm

Is there a way to override the default npm install script proposed by IntelliJ, I mean the one that appear as a notification when your package.json change or the one from the context menu when you right click the package.json.
I would like to add an option such as "--legacy-peer-deps".
Or do I have to run it through the terminal every time ?

this command can't be customized, so you have to either run the command in terminal or create the corresponding npm run configuration:

Related

When I run npm init, the package name is always scoped with my organization name by default. How to change this?

When I run "npm init" the package name always starts from #hackstrap/..., by default. Instead when I run the command package name should be "webpack-demo". How can I make this happen?
npm config delete scope --global
Running this command helped me solve the issue

How to pass inline options when running npx?

Without changing the global npm configuration of the workstation or creating an .npmrc file in the current directory, I want to run an npx package using a private nexus registry.
So, is it possible to run npx commands (preferably cross-paltform) with inline options like registry and strict-ssl? Something like:
npx somerunnablepackage --registry https://mynexus --strict-ssl false
I tried the snippet above on PowerShell/Windows, but my registry was not hit and it tried to reach the default registry (https://registry.npmjs.org) anyway.
Use
npm_config_registry=https://mynexus npm_config_strict_ssl=false npx somerunnablepackage
See https://docs.npmjs.com/misc/config

NPM Init and Start

I'm using npm for a local project and I want to know if I have to use npm init every time I start a session? I think the answer is yes.
If I restart my machine for example, do I have to do npm init? Do I have to do npm install and npm start each time?
Thanks
No, you only have to do npm init when you're first creating a project. It essentially just creates the package.json file (https://docs.npmjs.com/cli/init.html).
And you should only have to run npm install when you first set up a project for local development, or when changes are made to the project's dependencies. So, usually just once, unless you've made changes. (https://docs.npmjs.com/cli/install.html)
npm start is a script that should be defined in your package.json, and you will likely need to run that every time you begin local development on your project.
When you are creating a node project, you need to have package.json. npm init is a convenient way of scaffolding your package.json; you may need to run it everytime you are starting a new project.
npm install, however, installs your dependencies in node_modules folder. You may need to run this everytime you manually add a dependency to your package.json file.
If you need extra information, check here: https://nodesource.com/blog/an-absolute-beginners-guide-to-using-npm/
npm init is to make new modules you dont ever need to run npm init to start a session at all as far as I can tell

react-native: switch from yarn to npm

Is there a step-by-step process to change a react-native project from using yarn as the package manager to using npm? All I can find after several days of searching are instructions to go from npm to yarn and a package called deyarn which doesn't seem to fully work for me. Does anyone have a good resource on this?
Try this :
Remove yarn.lock (don't need this file).
Remove folder node_modules
In package.json, change script use yarn to the same command with npm
Remove all global package of yarn (don't need to remove if you want to use npm for one project)
Remove yarn if you don't want to use it again.
Install npm (if you installed, ignore this step)
Install global and local package you need
Can you upload some error, you said that not fully work.
Edit:
If you want to change npm to yarn, it same:
Remove package-lock.json (don't need this file).
Remove folder node_modules
In package.json, change script uses npm to the same command with yarn
Remove all global package of npm (don't need to remove if you want to use yarn for one project)
Remove npm if you don't want to use it again.
Install yarn (if you installed, ignore this step)
Install global and local package you need
You can see CLI commands comparison for 3rd step
You can try taking the following steps:
Remove node_modules
Run npm install
This should work because npm and yarn use the same package.json.
The deyarn package worked brilliantly for me.
Note that it will only flag (not auto-update) any package-lock.json scripts that you may need to update.
Depending on your environment needs, you may also want to strip out the engines: yarn: '..' entry it adds to your package-lock.json.
You don't need to do anything just run npm start cmd then follow the same step as suggest.
I've covert my yarn project To npm see the image.
enter image description here
enter image description here
hope is work for you.
thanks happy coding.

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