如下所示,有点蒙蔽了,求帮助:
HRX-MackBook:practice Ruxin$ sudo npm install -g gulp-imagemin
Password:
> gifsicle@3.0.4 postinstall /usr/local/lib/node_modules/gulp-imagemin/node_modules/gifsicle
> node lib/install.js
⚠ EACCES: permission denied, mkdir '/usr/local/lib/node_modules/gulp-imagemin/node_modules/gifsicle/vendor'
⚠ gifsicle pre-build test failed
ℹ compiling from source
/usr/local/lib/node_modules/gulp-imagemin/node_modules/onetime/index.js:15
throw new Error(fnName + ' can only be called once.');
^
Error: callback() can only be called once.
at onetime (/usr/local/lib/node_modules/gulp-imagemin/node_modules/onetime/index.js:15:11)
at /usr/local/lib/node_modules/gulp-imagemin/node_modules/download/index.js:156:5
at ConcatStream.<anonymous> (/usr/local/lib/node_modules/gulp-imagemin/node_modules/concat-stream/index.js:36:43)
at emitNone (events.js:110:20)
at ConcatStream.emit (events.js:207:7)
at finishMaybe (/usr/local/lib/node_modules/gulp-imagemin/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:607:14)
at endWritable (/usr/local/lib/node_modules/gulp-imagemin/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:615:3)
at ConcatStream.Writable.end (/usr/local/lib/node_modules/gulp-imagemin/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:571:41)
at DuplexWrapper.onend (/usr/local/lib/node_modules/gulp-imagemin/node_modules/stream-combiner2/node_modules/readable-stream/lib/_stream_readable.js:570:10)
at Object.onceWrapper (events.js:314:30)
> jpegtran-bin@3.2.0 postinstall /usr/local/lib/node_modules/gulp-imagemin/node_modules/jpegtran-bin
> node lib/install.js
⚠ EACCES: permission denied, mkdir '/usr/local/lib/node_modules/gulp-imagemin/node_modules/jpegtran-bin/vendor'
⚠ jpegtran pre-build test failed
ℹ compiling from source
/usr/local/lib/node_modules/gulp-imagemin/node_modules/onetime/index.js:15
throw new Error(fnName + ' can only be called once.');
^
Error: callback() can only be called once.
at onetime (/usr/local/lib/node_modules/gulp-imagemin/node_modules/onetime/index.js:15:11)
at /usr/local/lib/node_modules/gulp-imagemin/node_modules/download/index.js:156:5
at ConcatStream.<anonymous> (/usr/local/lib/node_modules/gulp-imagemin/node_modules/concat-stream/index.js:36:43)
at emitNone (events.js:110:20)
at ConcatStream.emit (events.js:207:7)
at finishMaybe (/usr/local/lib/node_modules/gulp-imagemin/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:607:14)
at endWritable (/usr/local/lib/node_modules/gulp-imagemin/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:615:3)
at ConcatStream.Writable.end (/usr/local/lib/node_modules/gulp-imagemin/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:571:41)
at DuplexWrapper.onend (/usr/local/lib/node_modules/gulp-imagemin/node_modules/stream-combiner2/node_modules/readable-stream/lib/_stream_readable.js:570:10)
at Object.onceWrapper (events.js:314:30)
> optipng-bin@3.1.4 postinstall /usr/local/lib/node_modules/gulp-imagemin/node_modules/optipng-bin
> node lib/install.js
⚠ EACCES: permission denied, mkdir '/usr/local/lib/node_modules/gulp-imagemin/node_modules/optipng-bin/vendor'
⚠ optipng pre-build test failed
ℹ compiling from source
/usr/local/lib/node_modules/gulp-imagemin/node_modules/onetime/index.js:15
throw new Error(fnName + ' can only be called once.');
^
Error: callback() can only be called once.
at onetime (/usr/local/lib/node_modules/gulp-imagemin/node_modules/onetime/index.js:15:11)
at /usr/local/lib/node_modules/gulp-imagemin/node_modules/download/index.js:156:5
at ConcatStream.<anonymous> (/usr/local/lib/node_modules/gulp-imagemin/node_modules/concat-stream/index.js:36:43)
at emitNone (events.js:110:20)
at ConcatStream.emit (events.js:207:7)
at finishMaybe (/usr/local/lib/node_modules/gulp-imagemin/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:607:14)
at endWritable (/usr/local/lib/node_modules/gulp-imagemin/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:615:3)
at ConcatStream.Writable.end (/usr/local/lib/node_modules/gulp-imagemin/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:571:41)
at DuplexWrapper.onend (/usr/local/lib/node_modules/gulp-imagemin/node_modules/stream-combiner2/node_modules/readable-stream/lib/_stream_readable.js:570:10)
at Object.onceWrapper (events.js:314:30)
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: gifsicle@3.0.4 (node_modules/gulp-imagemin/node_modules/gifsicle):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: gifsicle@3.0.4 postinstall: `node lib/install.js`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: jpegtran-bin@3.2.0 (node_modules/gulp-imagemin/node_modules/jpegtran-bin):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: jpegtran-bin@3.2.0 postinstall: `node lib/install.js`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: optipng-bin@3.1.4 (node_modules/gulp-imagemin/node_modules/optipng-bin):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: optipng-bin@3.1.4 postinstall: `node lib/install.js`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1
+ gulp-imagemin@3.3.0
added 281 packages and updated 1 package in 66.047s
未加 sudo 时:
HRX-MackBook:~ Ruxin$ npm install -g gulp-imagemin
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/gulp-imagemin/node_modules
npm ERR! path /usr/local/lib/node_modules/gulp-imagemin/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/gulp-imagemin/node_modules'
npm ERR! { Error: EACCES: permission denied, access '/usr/local/lib/node_modules/gulp-imagemin/node_modules'
npm ERR! stack: 'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules/gulp-imagemin/node_modules\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules/gulp-imagemin/node_modules' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/ruxin/.npm/_logs/2017-08-22T00_58_22_466Z-debug.log
本地环境版本:
node: v8.4.0;
npm: 5.3.0
有根据这个npm官方文档说明选项一操作,不过问题还是一样的。
npm官方文档对于这种问题有讲解,你改某个配置,把全局模块放到家目录这种有读写权限的位置就行了,以后都不用sudo.
https://docs.npmjs.com/gettin...