“npm config set prefix” fails on user owned directory in macOS Mojave

Posted on

QUESTION :

I am installing node on a clean macOS Mojave box using Homebrew. I am trying to set npm install directory in a user owned dir; the dir tools already exists and is owned by the user:

npm config set prefix '/Users/giorgio/tools/npm_global'

And that fails with this message. Does anyone know what is going on?

Error: EACCES: permission denied, mkdir '/tools'
TypeError: Cannot read property 'loaded' of undefined
    at exit (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:98:27)
    at errorHandler (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:216:3)
    at /usr/local/lib/node_modules/npm/bin/npm-cli.js:78:20
    at cb (/usr/local/lib/node_modules/npm/lib/npm.js:225:22)
    at /usr/local/lib/node_modules/npm/lib/npm.js:263:24
    at /usr/local/lib/node_modules/npm/lib/config/core.js:83:7
    at Array.forEach (<anonymous>)
    at /usr/local/lib/node_modules/npm/lib/config/core.js:82:13
    at f (/usr/local/lib/node_modules/npm/node_modules/once/once.js:25:25)
    at afterExtras (/usr/local/lib/node_modules/npm/lib/config/core.js:173:20)
/usr/local/lib/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 (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:98:27)
    at process.errorHandler (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:216:3)
    at process.emit (events.js:197:13)
    at process._fatalException (internal/process/execution.js:123:25)

ANSWER :

Found a solution quite randomly. Seems like the first time I tried to set prefix I did use a wrong path string. I had to manually remove the .npmrc file and retry the set prefix command to make it work.

I would really have expected set prefix to be able to modify the npn config files created by itself though.

Leave a Reply

Your email address will not be published. Required fields are marked *