Error: EPERM: operation not permitted

I am installing packages for NODEJS/NPM and am receiving the following error, which, apparently, is not an error with the software, but with my MAC. Please help as this is interfering with my projects.



Error: EPERM: operation not permitted, mkdir '/usr/loca'

TypeError: Cannot read property 'get' of undefined

at errorHandler (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:205:18)

at /usr/local/lib/node_modules/npm/bin/npm-cli.js:83:20

at cb (/usr/local/lib/node_modules/npm/lib/npm.js:214:22)

at /usr/local/lib/node_modules/npm/lib/npm.js:252:24

at /usr/local/lib/node_modules/npm/lib/config/core.js:81:7

at Array.forEach (<anonymous>)

at /usr/local/lib/node_modules/npm/lib/config/core.js:80: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:178:20)

at /usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:47:53

/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:205

if (npm.config.get('json')) {

^

Hi,

It's been 3 years to this Question and there isn't a clear solution to this over the internet. Maybe its too easy but I struggled with this for the last couple of hours and thought my answer here would help anyone who has a similar problem..

The issue started with -

% npm config set prefix /usr/loca

As you can notice from the above, I forgot the letter 'l' at the end of the line leading to npm config setting my 'prefix' to /usr/loca [this is my understanding of the issue. Feel free to correct me as I am new to Node world]

Now, when I try and run -

% npx create-react-app myApp

I got an error as -

Error: EPERM: operation not permitted, mkdir '/usr/loca'

Because there is no directory by name 'loca'.
Few suggestions about disabling SIP to make it work are there but I think it's not a good idea. Anyway, here are the steps I took to resolve the issue -

Step 1 : On your terminal get into root account by typing --> sudo -i
Step 2: Enter your root credential password
Step 3: Clear npm cache by force --> npm cache clean --force
Step 4: Install latest npm --> npm install -g npm@latest --force
Step 5: Clear npm cache again --> npm cache clean --force
Step 6: You should be good now. Check your npm version --> rpm -v
Step 7: 'exit' out of root
Step 8: Set prefix properly this time --> npm config set prefix /usr/local
Step 9: npx create-react-app client
Step 10: Type 'Y' to install create-react-app package
  • If everything went well, you should see a 'Happy Hacking' message as the last line.

Hope this helps.

Thank you @BK_Mais, the above solution worked for me.

Error: EPERM: operation not permitted
 
 
Q