如何在全局 npm 配置中重置 npm 注册表

是否可以更改或重置全局 npm 注册表。

感谢你的帮助。

117735 次浏览

Yes...

You can use this

$(npm config get globalconfig)
npm config --global edit

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!

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:

  1. npm config set registry https://registry.npmjs.org commands even with --location= set to project, user, global
  2. setting .npmrc with npm_config_registry=https://registry.npmjs.org value in multiple locations
  3. even yarn wouldn't change the registry and I also tried to use the yarn specific commands as well yarn config set ...
  4. restarting my system multiple times and re-trying all of the above in different ways

Information about my environment:

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