7

I accidentally changed the npm prefix to a place that doesn't exist. Is there a configuration file I can access that would allow me to change this back?

The only options I can think of are:

  1. Completely Uninstall Node (npm not responding after changing the prefix)
  2. I guess I could create the directories that don't exist and move the npm files there.

But it seems like there should be a config file I can change somewhere, right?

Community
  • 1
  • 1
Travis Heeter
  • 13,002
  • 13
  • 87
  • 129

2 Answers2

9

prefix can be defined per-install and other commands using --prefix, but as a global setting it is in ~/.npmrc (C:\Users\<your user name>\.npmrc). You can remove / edit it directly in that file.

You can also use npm config set prefix $value, or npm config delete prefix if you prefer.

li ki
  • 342
  • 3
  • 11
Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
  • Yeah, I used `config set prefix` when I changed it to the wrong directory. Now I can't use npm at all anymore. – Travis Heeter Oct 21 '16 at 13:54
  • OK, I looked through the `.nmprc` and `.npm-config` files (Yes, multiple files, they all look kinda different), and I'm not sure where the prefix is actually set. I'm not familiar with what type of file this is, but it looks like it's just documentation. – Travis Heeter Oct 21 '16 at 13:58
  • I saw these files because I didn't know that `~/` means *the User directory*, in my case `~` is `C:\Users\Travis`. I thought `~/` meant *the Node directory*, which would be `C:\Program Files\nodejs`. A really confusing thing is that `.nmprc` and `.npm-config` files exists in both of these locations. You need to edit the files in `C:\Users\`. – Travis Heeter Oct 21 '16 at 17:16
  • @TravisHeeter For npmrc, there are four places to put it: 1. per-project config file (/path/to/my/project/.npmrc). 2. per-user config file (~/.npmrc). 3. global config file ($PREFIX/etc/npmrc). 4. npm builtin config file (/path/to/npm/npmrc). See [npmrc | npm v7 Docs](https://docs.npmjs.com/cli/v7/configuring-npm/npmrc#files) for details. – li ki Sep 29 '21 at 13:46
0

Using this command you can set new prefix

npm config set prefix "C:\Users\{yourname}\AppData\Roaming\npm" --loglevel=verbose