0
votes

I am trying to install firebase and create-react-native-app on my terminal and keep getting the same errors on my terminal. Can someone please explain to me the root of my issue and a solution.

Please explain how i might be able to change my permissions

npm install -g create-react-native-app

npm install firebase-tools -g

npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules npm ERR! path /usr/local/lib/node_modules npm ERR! code EACCES npm ERR! errno -13 npm ERR! syscall access npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules' npm ERR! { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules'] npm ERR! stack: npm ERR! 'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules\'', npm ERR! errno: -13, npm ERR! code: 'EACCES', npm ERR! syscall: 'access', npm ERR! path: '/usr/local/lib/node_modules' } npm ERR! npm ERR! The operation was rejected by your operating system. npm ERR! It is likely you do not have the permissions to access this file as the current user npm ERR! npm ERR! If you believe this might be a permissions issue, please double-check the npm ERR! permissions of the file and its containing directories, or try running npm ERR! the command again as root/Administrator (though this is not recommended).

npm ERR! A complete log of this run can be found in: npm ERR! /Users/matthewsixt/.npm/_logs/2018-12-21T18_46_00_558Z-debug.log

1

1 Answers

0
votes

Can someone please explain to me the root of my issue

npm is trying to write to a directory it doesn't have permission to write to.

Please explain how i might be able to change my permissions

As you can read on the npm docs, if you see an EACCES error when you try to install a package globally, you can either manually change npm’s default directory or reinstall npm with a node version manager.

Change npm’s default directory

mkdir ~/.npm-global
npm config set prefix '~/.npm-global'

This creates a directory for global installations and configures npm to use the new directory path. Then create a ~/.profile file (or open it if one exists) and add:

export PATH=~/.npm-global/bin:$PATH

Reload your shell, then reattempt your install to check that it is working:

source ~/.profile
npm i -g create-react-native-app

Use a version manager

This is my preferred option, as you can install as many versions of Node and npm as you like and change between them at will. It also totally negates the permissions issue.

The version manager I use is nvm. To install it, there is a handy one-liner using cURL:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

To verify the install:

command -v nvm

which should output 'nvm' if the installation was successful.

There are also a bunch of other installation methods listed on the project's homepage.

Once you have it installed, you can see what versions of Node are available with:

nvm ls-remote

And install a version using:

nvm install xx.xx.xx

(where xx.xx.xx is the version number).

If you'd like to read more about using nvm, this article is helpful: Installing Multiple Versions of Node.js Using nvm.

Using sudo

You'll probably find that prefixing sudo to your command fixes the issue. However, please don't do this.

Installing random code from the internet with admin rights is a really, really bad idea.