I can’t show the version of an NPM package (nodemon --version), what to do? - npm

I tried to run codes in my hyper-terminal (deleted nodemon and then reinstalled it) but at the end I still can NOT get the version of my nodemon, it says:
"C:\Users\azadk\AppData\Roaming\npm/node_modules/node/bin/node: line 1: This: command not found"
Here’s what I tried to do:
I also tried to set the path of Environment variables to "C:\Program Files\nodejs" but still I can’t get the version.

If you are connected to some sort of VPN or your corporate internet, try to connect to another network and run the call again.

I entered these commands and the problem was resolved:
npm config rm proxy
npm config rm https-proxy
npm config delete http-proxy
npm config delete https-proxy
set HTTP_PROXY=null
set HTTPS_PROXY=null

Related

Errors setting npm proxy config

I tried various npm config but all failed:
registry=http://registry.npmjs.org/
proxy=http://host:8080/
https-proxy=http://host:8080/
strict-ssl=false
This failed with 418 I'm a teapot error.
registry=https://registry.npmjs.org/
proxy=http://host:8080/
https-proxy=http://host:8080/
strict-ssl=false
This just failed to connect.(ECONNRESET)
registry=https://registry.npmjs.org/
proxy=http://host:8080/
https-proxy=https://host:8080/
strict-ssl=false
Finally this failed with:
write EPROTO 140588447455040:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:252:
How should I set config to install packages through proxy server?
npm version : 6.4.1
OS : ubuntu 18.0.4
I ran into the same issue trying to install gulp.
There is something weird about proxy configuration in npm. It appears that old versions of the proxy & https-proxy settings persist somehow, even if they're not in the config. For me, an old proxy setting, with a previous, expired, password was still present, even after I tried deleting via "npm config delete proxy".
What worked for me was to use
npm config edit
then add in valid entries for proxy and https-proxy. e.g.
proxy=http://[username]:[password]#[proxyhost]:8080/
https-proxy=http://[username]:[password]#[proxyhost]:8080/
It seemed that the https-proxy line was the one that got it working.

How to fix timeout for packages on `npm install`?

When I run npm install it seems to work fine until part way installing packages. It seems to have no problem with the first half, but then after a while it will fail to be able to reach other packages. I just get the repeating errors, eg:
npm http request GET https://registry.npmjs.org/react-hot-loader
npm info attempt registry request try #3 at 6:43:34 AM
npm http request GET https://registry.npmjs.org/react-tap-event-plugin
npm info attempt registry request try #3 at 6:43:34 AM
npm http request GET https://registry.npmjs.org/react-test-renderer
etc.
It will continue to do this for an hour and and then the install will fail.
The install breaks at a different package each time so I don't think it's a problem with a particular file.
I can access these files fine with my browser and curl.
My work has a firewall but this domain is whitelisted.
Would anyone know what I could do to get this to work or what could be causing it?
If it's about the timing problem you should find a speed solutions for npm install.
So you can try these faster command than npm install :
pnpm install %70 faster
or
npm install --no-audit 15% faster
or
npm install --prefer-offline --no-audit 15% faster
check this article for details : speeding up npm install
You can override the max and min timeout in ~/.npmrc.
// npm config ls -l
// add these 2 lines in ~/.npmrc
fetch-retry-maxtimeout = 6000000
fetch-retry-mintimeout = 1000000
If your internet connection is the problem, try increasing the timeout:
npm config set timeout 6000000
The value is a 32-bit int.
If it's still relevant or maybe for other people of interest: For me it helped, deleting the package.lock file and running npm cache clean --force.
It might not be your case, but I had issues with a package being hosted at github with the repo url being only with git protocol (port 9418 not usually open on firewall).
Once added that to the firewall I could npm install without issues.
You can view the repository url with:
$ npm view zone.js repository.url
git://github.com/angular/angular.git
I saw an answer earlier that can resolve your problem by overriding the max and min timeout in ~/.npmrc file, but some didn't understand how to do it.
First go to the nodejs folder - for me it's located at ( Y:\Program Files\nodejs )
Open the node_modules folder.
Then npm folder.
Select (.npmrc) file + right click and open it with any text editor you want.
Finally add these 2 lines and click Ctrl+S
fetch-retry-maxtimeout = 6000000
fetch-retry-mintimeout = 1000000
.npmrc file after modification
npm cache clean --force
npm install --force
It works fine.
If you are on windows, try running vscode as administrator, it worked for me, I tried npm config delete https-proxy , npm config delete proxy and , tried deleting node_modules, and package.lock.json and ran npm cache clean --force but at last ran vscode as adminitrator before deleting node_modules and package.lock.json, it worked
I solved the timeout issue by executing these commands:
rm package-lock.json
npm i

How to install files using npm behind proxy?

While running the npm install command, I'm getting:
ERR 418 I m a teapot
I set a proxy but I'm not sure whether it is correctly parsed. I doubt that the proxy might be the reason. Can someone help me on this? I also ran npm config get proxy.
Try something like this:
npm config set proxy 213.169.158.34:8080
npm config set https-proxy 213.169.158.34:443
npm config set registry http://registry.npmjs.org/
npm instal

Cannot install node-sass

I'm in an environment where I am required to run a local proxy, and I am unable to install node-sass. When I try the following:
npm install -g node-sass
I get an error:
Cannot download "https://github.com/sass/node-sass/releases/download/v4.5.3/win32-x64-48_binding.node": tunneling socket could not be established, cause=read ECONNRESET
I have already installed cntlm and configured it correctly. To verify I use the porxy server to access internet and it works fine.
The following environment variables are set
http_proxy -> http://localhost:3128
https_proxy -> http://localhost:3128
Have also added the following to my .npmrc
https-proxy=http://localhost:3128
http-proxy=http://localhost:3128
proxy=http://localhost:3128
Also tried by adding slashes to the end but the result is the same.
Any clues and help would be appreciated since I have no idea how to resolve this.
Additional details:
node -v
v6.11.4
npm -v
5.5.1
The workaround I found was to download the node-sass file from https://github.com/sass/node-sass/releases/download/v4.5.3/win32-x64-48_binding.node and then set the sass-path to the binaries downloaded:
SET_SASS_BINARY_PATH = C:\..\..\
and then doing
npm install -g node-sass
worked for me.

How to reset the npm registry in global npm config

Is there any way to change or reset the global npm registry.
Appreciate your assistance.
Run the following command in your terminal to revert back to the default regsitry
npm config set registry https://registry.npmjs.org/
or
npm config delete registry
NPM CONFIG DOCS
If you are on windows, other than setting the registry, you can also delete the .npmrc file to reset the registry.
You can find this file at C:\Users\<Your User Name>\.npmrc
Sets a configuration key to a value
npm config set <key> <value> [-g|--global]
Gets the value of an existing configuration key
npm config get <key>
Deletes the key from all configuration files.
npm config delete <key>
Lists all the config settings,could be used to check for existing config entries
npm config list
Opens the config file in an editor.
npm config edit
All that would help make changes to the npm registry
Source
Hope that helps!
Yes...
You can use this
$(npm config get globalconfig)
npm config --global edit
In my experience, I had to use a private NPM registry for security reasons and while switching projects I had to change my registry and found that I was unable to! A requirement of the private registry was to be on a VPN network so to be able to connect to the private registry.
Command I was trying to run
npx sb init --builder webpack5
I was trying to install storybook in an existing project.
I tried and failed by:
npm config set registry https://registry.npmjs.org commands even with --location= set to project, user, global
setting .npmrc with npm_config_registry=https://registry.npmjs.org value in multiple locations
even yarn wouldn't change the registry and I also tried to use the yarn specific commands as well yarn config set ...
restarting my system multiple times and re-trying all of the above in different ways
Information about my environment:
OSX, NVM (Node Version Manager), using npm not yarn
What ended up fixing my problem
2. I ended up reconnecting to the VPN so that when I ran my npx ... command from above it would still download the packages through my private registry
3. rm -rf node_modules package-lock.json I removed the installed files and lockfile
4. I disconnected from my VPN and re-installed packages with the same npx ... command
5. I see now that the packages are properly pulling from https://registry.npmjs.org
For some reason NPM wanted to resolve something from the private registry I had before finally using the newly configured public registry.
Might be a bug with NPM that I do not have the experience nor time to troubleshoot though I wanted to share my experience here in hopes it will help someone with a similar experience.