NPM安装gulp --save-dev错误

时间:2014-09-12 15:17:53

标签: npm gulp

当我运行命令时,我正在尝试使用Gulp.js设置项目:

npm install gulp --save-dev

我收到了错误:

npm WARN package.json htdocs@0.0.0 No repository field.
npm WARN package.json gulp-uglify@1.0.1 No README data
npm WARN package.json gulp@3.8.8 No README data
npm ERR! Error: EACCES, chown '/path/to/dir/htdocs/node_modules/gulp/package.json'
npm ERR!     at Error (native)
npm ERR!  { [Error: EACCES, chown '/path/to/dir/htdocs/node_modules/gulp/package.json']
npm ERR!   stack: 'Error: EACCES, chown \'/path/to/dir/htdocs/node_modules/gulp/package.json\'\n    at Error (native)',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/path/to/dir/htdocs/node_modules/gulp/package.json',
npm ERR!   fstream_finish_call: 'chown',
npm ERR!   fstream_type: 'File',
npm ERR!   fstream_path: '/path/to/dir/htdocs/node_modules/gulp/package.json',
npm ERR!   fstream_class: 'FileWriter',
npm ERR!   fstream_stack:
npm ERR!    [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/writer.js:308:19',
npm ERR!      '/usr/local/lib/node_modules/npm/node_modules/graceful-fs/polyfills.js:143:7',
npm ERR!      'Object.oncomplete (evalmachine.<anonymous>:93:15)' ] }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

npm ERR! System Linux 3.0.0-12-generic-pae
npm ERR! command "node" "/usr/local/bin/npm" "install" "gulp" "--save-dev"
npm ERR! cwd /path/to/dir/htdocs
npm ERR! node -v v0.13.0-pre
npm ERR! npm -v 1.4.26
npm ERR! path /path/to/dir/htdocs/node_modules/gulp/package.json
npm ERR! fstream_path /path/to/dir/htdocs/node_modules/gulp/package.json
npm ERR! fstream_type File
npm ERR! fstream_class FileWriter
npm ERR! fstream_finish_call chown
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! stack Error: EACCES, chown '/path/to/dir/htdocs/node_modules/gulp/package.json'
npm ERR! stack     at Error (native)
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/fstream/lib/writer.js:308:19
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/graceful-fs/polyfills.js:143:7
npm ERR! fstream_stack Object.oncomplete (evalmachine.<anonymous>:93:15)
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /path/to/dir/htdocs/npm-debug.log
npm ERR! not ok code 0

这是我的package.json文件

{
  "name": "htdocs",
  "version": "0.0.0",
  "description": "",
  "main": "gulpfile.js",
  "dependencies": {
    "gulp": "^3.8.8",
    "gulp-uglify": "1.0.1"
  },
  "devDependencies": {
    "gulp": "^3.8.8",
    "gulp-uglify": "1.0.1"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

我在网上找到了一些有类似问题的人,修复程序建议运行命令:

  

sudo chown -R whoami〜/ .npm   但这并没有解决我的问题。

有谁知道这可能是什么原因和解决方案?

3 个答案:

答案 0 :(得分:2)

我在OSX上遇到了同样的问题,我修复了它的执行:

sudo chown -R $USER:$GROUP ~/.npm

npm cache clean

然后我可以在项目中安装包含--save-dev的软件包。

来源:https://github.com/npm/npm/issues/5869

答案 1 :(得分:0)

npm必须能够写入路径/path/to/dir/htdocs/node_modules/,其中(您的)节点写入其模块。

您有两个经常使用的选项来修复这些权限:

  • 为每个人安装一个gulp

    sudo npm install -g gulp
    
  • 为项目保存gulp

    (sudo if necessary) chmod u+rw /path/to/dir/htdocs/node_modules/
    npm install gulp --save-dev
    

    您可能还需要修复父目录的权限。

如果其他人有更好的想法,请告诉我。

答案 2 :(得分:0)

运行 npm install npm @ latest -g 并更新到最新版本为我解决了问题:)