【已解决】npm安装yarn react-native-cli时出错:npm ERR Error EACCES permission denied

折腾:

【记录】折腾React Native iOS

期间,

➜  ~ npm install -g yarn react-native-cli
npm ERR! tar.unpack untar error /Users/crifan/.npm/yarn/0.21.3/package.tgz
npm ERR! tar.unpack untar error /Users/crifan/.npm/react-native-cli/2.0.1/package.tgz
npm ERR! Darwin 16.4.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "yarn" "react-native-cli"
npm ERR! node v4.4.7
npm ERR! npm  v2.15.8
npm ERR! path /usr/local/lib/node_modules/yarn
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall mkdir
npm ERR! Error: EACCES: permission denied, mkdir ‘/usr/local/lib/node_modules/yarn’
npm ERR!     at Error (native)
npm ERR!  { [Error: EACCES: permission denied, mkdir ‘/usr/local/lib/node_modules/yarn’]
npm ERR!   errno: -13,
npm ERR!   code: ‘EACCES’,
npm ERR!   syscall: ‘mkdir’,
npm ERR!   path: ‘/usr/local/lib/node_modules/yarn’,
npm ERR!   fstream_type: ‘Directory’,
npm ERR!   fstream_path: ‘/usr/local/lib/node_modules/yarn’,
npm ERR!   fstream_class: ‘DirWriter’,
npm ERR!   fstream_stack:
npm ERR!    [ ‘/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:35:25’,
npm ERR!      ‘/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:47:53’,
npm ERR!      ‘FSReqWrap.oncomplete (fs.js:82:15)’ ] }
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/crifan/npm-debug.log
➜  ~

 

参考文档去:

sudo chown -R `whoami` /usr/local

就可以继续了:

➜  ~ npm install -g yarn react-native-cli
/usr/local/bin/react-native -> /usr/local/lib/node_modules/react-native-cli/index.js
/usr/local/bin/yarn -> /usr/local/lib/node_modules/yarn/bin/yarn.js
/usr/local/bin/yarnpkg -> /usr/local/lib/node_modules/yarn/bin/yarn.js
react-native-cli@2.0.1 /usr/local/lib/node_modules/react-native-cli
├── semver@5.3.0
├── minimist@1.2.0
├── chalk@1.1.3 (escape-string-regexp@1.0.5, supports-color@2.0.0, ansi-styles@2.2.1, strip-ansi@3.0.1, has-ansi@2.0.0)
└── prompt@0.2.14 (revalidator@0.1.8, pkginfo@0.4.0, read@1.0.7, winston@0.8.3, utile@0.2.1)
yarn@0.21.3 /usr/local/lib/node_modules/yarn
├── ini@1.3.4
├── strip-bom@3.0.0
├── detect-indent@5.0.0
├── camelcase@3.0.0
├── request-capture-har@1.1.4
├── leven@2.1.0
├── roadrunner@1.1.0
├── bytes@2.4.0
├── semver@5.3.0
├── object-path@0.11.4
├── death@1.1.0
├── is-builtin-module@1.0.0 (builtin-modules@1.1.1)
├── commander@2.9.0 (graceful-readlink@1.0.1)
├── defaults@1.0.3 (clone@1.0.2)
├── chalk@1.1.3 (escape-string-regexp@1.0.5, supports-color@2.0.0, ansi-styles@2.2.1, has-ansi@2.0.0, strip-ansi@3.0.1)
├── read@1.0.7 (mute-stream@0.0.7)
├── is-ci@1.0.10 (ci-info@1.0.0)
├── node-emoji@1.5.1 (string.prototype.codepointat@0.2.0)
├── cmd-shim@2.0.2 (graceful-fs@4.1.11)
├── validate-npm-package-license@3.0.1 (spdx-expression-parse@1.0.4, spdx-correct@1.0.2)
├── debug@2.6.1 (ms@0.7.2)
├── minimatch@3.0.3 (brace-expansion@1.1.6)
├── loud-rejection@1.6.0 (signal-exit@3.0.2, currently-unhandled@0.4.1)
├── mkdirp@0.5.1 (minimist@0.0.8)
├── proper-lockfile@2.0.0 (graceful-fs@4.1.11, retry@0.10.1)
├── invariant@2.2.2 (loose-envify@1.3.1)
├── tar-stream@1.5.2 (xtend@4.0.1, bl@1.2.0, end-of-stream@1.1.0, readable-stream@2.2.3)
├── rimraf@2.6.1 (glob@7.1.1)
├── tar@2.2.1 (inherits@2.0.3, block-stream@0.0.9, fstream@1.0.10)
├── request@2.79.0 (tunnel-agent@0.4.3, aws-sign2@0.6.0, oauth-sign@0.8.2, forever-agent@0.6.1, is-typedarray@1.0.0, caseless@0.11.0, isstream@0.1.2, stringstream@0.0.5, aws4@1.6.0, extend@3.0.0, json-stringify-safe@5.0.1, uuid@3.0.1, qs@6.3.1, combined-stream@1.0.5, mime-types@2.1.14, tough-cookie@2.3.2, form-data@2.1.2, hawk@3.1.3, http-signature@1.1.1, har-validator@2.0.6)
├── node-gyp@3.5.0 (graceful-fs@4.1.11, which@1.2.12, glob@7.1.1, nopt@3.0.6, osenv@0.1.4, fstream@1.0.10, npmlog@4.0.2)
├── inquirer@3.0.6 (ansi-escapes@1.4.0, through@2.3.8, strip-ansi@3.0.1, mute-stream@0.0.7, cli-width@2.1.0, figures@2.0.0, run-async@2.3.0, string-width@2.0.0, external-editor@2.0.1, cli-cursor@2.1.0, rx@4.1.0, lodash@4.17.4)
└── babel-runtime@6.23.0 (regenerator-runtime@0.10.3, core-js@2.4.1)

【总结】

此处,安装React Native期间:

npm install -g yarn react-native-cli

出现错误:

npm ERR! Error: EACCES: permission denied

原因是没有访问权限。

解决办法:

sudo chown -R `whoami` /usr/local

再重新安装,即可。



发表评论

电子邮件地址不会被公开。 必填项已用*标注

无觅相关文章插件,快速提升流量