我一直在尝试使用react native并创建一个项目,但却无法这样做。
我正在使用https://facebook.github.io/react-native/docs/getting-started.html
中的说明节点和守望者已经安装,然后我输入:
npm install -g react-native-cli
我明白了:
/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)
当我尝试做的时候:
react-native init AwesomeProject
我明白了:
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
如何防止错误?
我正在使用Mac。
我在命令的开头使用了sudo。但是当我这样做的时候:
cd AwesomeProject
react-native run-ios
我得到了:
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
我在开始时尝试使用sudo,我得到了这个:
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
答案 0 :(得分:2)
尝试使用sudo
启动命令,它将为您的命令提供在必要位置创建目录的权限。
答案 1 :(得分:0)
如果您使用的是Windows,请尝试使用管理员权限打开命令行。
如果你在mac或linux上,请在命令开头输入sudo。
无论哪种方式。确保目标目录不存在。
答案 2 :(得分:0)
对我来说,marked
目录中的.npm
目录属于root:wheel
。尝试将其取回;)(或0.3.*
内的marked
目录)
chown -R `whoami` ~/.npm/marked
或者必要时
sudo chown -R `whoami` ~/.npm/marked