npm的权限问题

时间:2017-07-27 17:50:11

标签: reactjs npm

我一直在尝试安装某些软件包时遇到权限问题,现在尝试使用npm install -g now-serve进行安装,并收到以下EACCESS错误:

npm WARN deprecated now-serve@0.5.1: This package is now deprecated! Please read this: https://zeit.co/blog/now-static
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
/usr/local/lib
└─┬ now-serve@0.5.1
  ├─┬ args@2.1.0
  │ ├── camelcase@3.0.0
  │ ├─┬ loud-rejection@1.6.0
  │ │ ├─┬ currently-unhandled@0.4.1
  │ │ │ └── array-find-index@1.0.2
  │ │ └── signal-exit@3.0.2
  │ ├── minimist@1.2.0
  │ └── pkginfo@0.4.0
  ├─┬ chalk@1.1.3
  │ ├── ansi-styles@2.2.1
  │ ├── escape-string-regexp@1.0.5
  │ ├─┬ has-ansi@2.0.0
  │ │ └── ansi-regex@2.1.1
  │ ├── strip-ansi@3.0.1
  │ └── supports-color@2.0.0
  ├─┬ fs-extra@0.30.0
  │ ├── graceful-fs@4.1.11
  │ ├── jsonfile@2.4.0
  │ ├── klaw@1.3.1
  │ ├── path-is-absolute@1.0.1
  │ └─┬ rimraf@2.6.1
  │   └─┬ glob@7.1.2
  │     ├── fs.realpath@1.0.0
  │     ├─┬ inflight@1.0.6
  │     │ └── wrappy@1.0.2
  │     ├── inherits@2.0.3
  │     ├─┬ minimatch@3.0.4
  │     │ └─┬ brace-expansion@1.1.8
  │     │   ├── balanced-match@1.0.0
  │     │   └── concat-map@0.0.1
  │     └── once@1.4.0
  ├─┬ hasbin@1.2.3
  │ └── async@1.5.2
  ├─┬ md5@2.2.1
  │ ├── charenc@0.0.2
  │ ├── crypt@0.0.2
  │ └── is-buffer@1.1.5
  ├─┬ tmp@0.0.29
  │ └── os-tmpdir@1.0.2
  └─┬ walk@2.3.9
    └── foreachasync@3.0.0

npm ERR! Darwin 16.6.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "now-serve"
npm ERR! node v6.11.0
npm ERR! npm  v3.10.10
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!     at Error (native)
npm ERR!  { Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!     at Error (native)
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules' }
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/carlosgrijalva/Code/React for Beginners/React-For-Beginners-Starter-Files-master/catch-of-the-day/npm-debug.log

我设法使用sudo进行安装,但在命令行中运行now时,zsh无法识别它。同样的事情发生在gulp上,如何更改权限问题?

这是我的package.json:

{
  "name": "cotd",
  "version": "0.0.1",
  "private": true,
  "devDependencies": {
    "autoprefixer-stylus": "0.10.0",
    "babel-eslint": "^7.1.1",
    "concurrently": "3.0.0",
    "eslint": "^3.12.2",
    "eslint-plugin-flowtype": "^2.29.1",
    "eslint-plugin-jsx-a11y": "^3.0.2",
    "eslint-plugin-react": "^6.8.0",
    "react-scripts": "0.6.1",
    "stylus": "0.54.5"
  },
  "dependencies": {
    "history": "4.2.0",
    "re-base": "2.2.0",
    "react": "15.3.2",
    "react-addons-css-transition-group": "15.3.2",
    "react-dom": "15.3.2",
    "react-router": "4.0.0-alpha.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "watch": "concurrently --names \"webpack, stylus\" --prefix name \"npm run start\" \"npm run styles:watch\"",
    "build": "react-scripts build",
    "eject": "react-scripts eject",
    "styles": "stylus -u autoprefixer-stylus ./src/css/style.styl -o ./src/css/style.css",
    "styles:watch": "stylus -u autoprefixer-stylus -w ./src/css/style.styl -o ./src/css/style.css"
  },
  "eslintConfig": {
    "extends": "./node_modules/react-scripts/.eslintrc"
  }
}

1 个答案:

答案 0 :(得分:0)

全局安装任何npm软件包时,它存储在/ usr / local / lib / node_modules文件夹中。它只能由root用户访问。我认为gulp配置没有任何问题,而是尝试以root用户身份登录,然后安装该软件包。如果仍然没有解决错误,请尝试检查系统的sudoers文件。