dozo dozo - 1 month ago 9
Node.js Question

Error trying to create a project using React Native

I have been trying to use react native and create a project but have not been able to do so.

I am using the instructions from https://facebook.github.io/react-native/docs/getting-started.html

Node and watchman are already installed and then when I enter:

npm install -g react-native-cli


I get this:

/usr/local/bin/react-native -> /usr/local/lib/node_modules/react-native-cli/index.js
react-native-cli@1.0.0 /usr/local/lib/node_modules/react-native-cli
├── semver@5.3.0
├── minimist@1.2.0
├── chalk@1.1.3 (ansi-styles@2.2.1, escape-string-regexp@1.0.5, supports-color@2.0.0, has-ansi@2.0.0, strip-ansi@3.0.1)
└── prompt@0.2.14 (revalidator@0.1.8, pkginfo@0.4.0, read@1.0.7, winston@0.8.3, utile@0.2.1)


When I try to do:

react-native init AwesomeProject


I get:

This will walk you through creating a new React Native project in /Users/jaimito/AwesomeProject
Installing react-native package from npm...

npm WARN peerDependencies The peer dependency react@~15.2.1 included from react-native will no
npm WARN peerDependencies longer be automatically installed to fulfill the peerDependency
npm WARN peerDependencies in npm 3+. Your application will need to depend on it explicitly.
npm ERR! Darwin 15.6.0
npm ERR! argv "/usr/local/Cellar/node/6.4.0/bin/node" "/usr/local/bin/npm" "install" "--save" "--save-exact" "react-native"
npm ERR! node v6.4.0
npm ERR! npm v2.15.9
npm ERR! path /Users/jaimito/.npm/optimist/0.6.1
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall mkdir

npm ERR! Error: EACCES: permission denied, mkdir '/Users/jaimito/.npm/optimist/0.6.1'
npm ERR! at Error (native)
npm ERR! { Error: EACCES: permission denied, mkdir '/Users/jaimito/.npm/optimist/0.6.1'
npm ERR! at Error (native)
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/Users/jaimito/.npm/optimist/0.6.1',
npm ERR! parent: 'react-native' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

npm ERR! Please include the following file with any support request:
npm ERR! /Users/jaimito/AwesomeProject/npm-debug.log

`npm install --save --save-exact react-native` failed


How do I prevent the errors?

I am working on a Mac.

I used sudo at the beginning of the command. But when I did:

cd AwesomeProject
react-native run-ios


I got:

fs.js:640
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
^

Error: EACCES: permission denied, open '/Users/jaimito/.babel.json'
at Error (native)
at Object.fs.openSync (fs.js:640:18)
at Object.fs.writeFileSync (fs.js:1333:33)
at save (/Users/jaimito/AwesomeProject/node_modules/react-native/node_modules/babel-register/lib/cache.js:53:16)
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
at Module.runMain (module.js:592:11)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3


I tried using sudo at the beginning and I got this:

fs.js:640
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
^

Error: EACCES: permission denied, open '/Users/jaimito/.babel.json'
at Error (native)
at Object.fs.openSync (fs.js:640:18)
at Object.fs.writeFileSync (fs.js:1333:33)
at save (/Users/jaimito/AwesomeProject/node_modules/react-native/node_modules/babel-register/lib/cache.js:53:16)
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
at Module.runMain (module.js:592:11)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
~
Process terminated. Press <enter> to close the window

Answer

Try starting the command with sudo, it'll give your command the permission to create directories in the necessary places.