17

I edited the npm config file with npm edit config. I made a syntax error in it and saved the file. Now, no matter what I try with npm, it will complain about it. I know what the syntax is and I would like to fix it, but I can't find the file anywhere.

C:\Users\Arthur>npm
Error: Failed parsing JSON config key cache: "C:\Users\Le Roi Arthur\AppData\Roaming\npm-cache"
    at parseField (D:\nodejs\node_modules\npm\lib\config\core.js:376:13)
    at D:\nodejs\node_modules\npm\lib\config\core.js:330:24
    at Array.forEach (<anonymous>)
    at Conf.add (D:\nodejs\node_modules\npm\lib\config\core.js:328:23)
    at ConfigChain.addString (D:\nodejs\node_modules\npm\node_modules\config-chain\index.js:244:8)
    at Conf.<anonymous> (D:\nodejs\node_modules\npm\lib\config\core.js:316:10)
    at D:\nodejs\node_modules\npm\node_modules\graceful-fs\graceful-fs.js:90:16
    at FSReqWrap.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:53:3)
TypeError: Cannot read property 'loaded' of undefined
    at exit (D:\nodejs\node_modules\npm\lib\utils\error-handler.js:98:27)
    at errorHandler (D:\nodejs\node_modules\npm\lib\utils\error-handler.js:216:3)
    at D:\nodejs\node_modules\npm\bin\npm-cli.js:77:20
    at cb (D:\nodejs\node_modules\npm\lib\npm.js:225:22)
    at D:\nodejs\node_modules\npm\lib\npm.js:263:24
    at D:\nodejs\node_modules\npm\lib\config\core.js:83:7
    at Array.forEach (<anonymous>)
    at Conf.<anonymous> (D:\nodejs\node_modules\npm\lib\config\core.js:82:13)
    at Conf.f (D:\nodejs\node_modules\npm\node_modules\once\once.js:25:25)
    at Object.onceWrapper (events.js:286:20)
D:\nodejs\node_modules\npm\lib\utils\error-handler.js:98
  var doExit = npm.config.loaded ? npm.config.get('_exit') : true
                          ^

TypeError: Cannot read property 'loaded' of undefined
    at exit (D:\nodejs\node_modules\npm\lib\utils\error-handler.js:98:27)
    at process.errorHandler (D:\nodejs\node_modules\npm\lib\utils\error-handler.js:216:3)
    at process.emit (events.js:198:13)
    at process._fatalException (internal/bootstrap/node.js:496:27)
Error: Failed parsing JSON config key cache: "C:\Users\Le Roi Arthur\AppData\Roaming\npm-cache"
    at parseField (D:\nodejs\node_modules\npm\lib\config\core.js:376:13)
    at D:\nodejs\node_modules\npm\lib\config\core.js:330:24
    at Array.forEach (<anonymous>)
    at Conf.add (D:\nodejs\node_modules\npm\lib\config\core.js:328:23)
    at ConfigChain.addString (D:\nodejs\node_modules\npm\node_modules\config-chain\index.js:244:8)
    at Conf.<anonymous> (D:\nodejs\node_modules\npm\lib\config\core.js:316:10)
    at D:\nodejs\node_modules\npm\node_modules\graceful-fs\graceful-fs.js:90:16
    at FSReqWrap.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:53:3)
TypeError: Cannot read property 'loaded' of undefined
    at exit (D:\nodejs\node_modules\npm\lib\utils\error-handler.js:98:27)
    at errorHandler (D:\nodejs\node_modules\npm\lib\utils\error-handler.js:216:3)
    at D:\nodejs\node_modules\npm\bin\npm-cli.js:77:20
    at cb (D:\nodejs\node_modules\npm\lib\npm.js:225:22)
    at D:\nodejs\node_modules\npm\lib\npm.js:263:24
    at D:\nodejs\node_modules\npm\lib\config\core.js:83:7
    at Array.forEach (<anonymous>)
    at Conf.<anonymous> (D:\nodejs\node_modules\npm\lib\config\core.js:82:13)
    at Conf.f (D:\nodejs\node_modules\npm\node_modules\once\once.js:25:25)
    at Object.onceWrapper (events.js:286:20)
D:\nodejs\node_modules\npm\lib\utils\error-handler.js:98
  var doExit = npm.config.loaded ? npm.config.get('_exit') : true
                          ^

TypeError: Cannot read property 'loaded' of undefined
    at exit (D:\nodejs\node_modules\npm\lib\utils\error-handler.js:98:27)
    at process.errorHandler (D:\nodejs\node_modules\npm\lib\utils\error-handler.js:216:3)
    at process.emit (events.js:198:13)
    at process._fatalException (internal/bootstrap/node.js:496:27)

Uninstalling and re-installing nodeJS doesn't fix the issue, the file is stored in cache somewhere. It's infuriately frustrating how hard it is to put my hands on that file.

Where can I find the npm config file ?

4

2 Answers 2

33

You need to edit npmrc file, take a look at documentation it will help you to find the appropriate one.

The four relevant files are:

  • Per-project config file: /path/to/my/project/.npmrc
  • Per-user config file: ~/.npmrc
  • Global config file: $PREFIX/npmrc
  • Built-in npm config file: /path/to/npm/npmrc
2
  • 7
    Thanks for the tip ! In my case, under Windows, the file was under C:\Users\{USERNAME}\AppData\Roaming\npm\etc\npmrc. Commented Oct 10, 2019 at 4:52
  • Woah, you just saved me.... windows - my edits were found under %userprofile%\.npmrc!
    – C4d
    Commented May 9, 2023 at 7:40
17

you can see the config file (and other) paths with the below command

npm config list
4
  • 3
    As stated in the original post, any command using npm will fail because of this syntax error, so npm config list is not a valid solution. Commented Aug 17, 2021 at 18:55
  • 1
    Oops, my bad... my google search for npm config file path for some reason brought this page (I guess because of the question title). Leaving it here, in case someone finds this interesting Commented Aug 17, 2021 at 21:47
  • I'm glad for this response because it answers the title question for most people seeking an answer.
    – Nathan Fig
    Commented Jun 22, 2022 at 19:51
  • 1
    You can also add the -l flag at the end of the command to have the complete list of parameters. npm config list -l
    – hdev
    Commented Jan 9, 2023 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.