node.js - nodejs安装http-server出错
PHPz
PHPz 2017-04-17 11:43:22
0
1
582

安装以及出错误提示如下:

mbp:~ wfp$ npm install http-server -g
npm ERR! tar.unpack untar error /Users/wfp/.npm/http-server/0.8.0/package.tgz
npm ERR! Darwin 14.1.1
npm ERR! argv "node" "/usr/local/bin/npm" "install" "http-server" "-g"
npm ERR! node v0.12.2
npm ERR! npm  v2.7.4
npm ERR! path /usr/local/lib/node_modules/http-server
npm ERR! code EACCES
npm ERR! errno -13

npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/http-server'
npm ERR!     at Error (native)
npm ERR!  { [Error: EACCES, mkdir '/usr/local/lib/node_modules/http-server']
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/usr/local/lib/node_modules/http-server',
npm ERR!   fstream_type: 'Directory',
npm ERR!   fstream_path: '/usr/local/lib/node_modules/http-server',
npm ERR!   fstream_class: 'DirWriter',
npm ERR!   fstream_stack: 
npm ERR!    [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23',
npm ERR!      '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:46:53',
npm ERR!      'FSReqWrap.oncomplete (fs.js:95: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/wfp/npm-debug.log

日志记录如下:

0 info it worked if it ends with ok
1 verbose cli [ 'node', '/usr/local/bin/npm', 'install', 'http-server', '-g' ]
2 info using npm@2.7.4
3 info using node@v0.12.2
4 silly cache add args [ 'http-server', null ]
5 verbose cache add spec http-server
6 silly cache add parsed spec { raw: 'http-server',
6 silly cache add   scope: null,
6 silly cache add   name: 'http-server',
6 silly cache add   rawSpec: '',
6 silly cache add   spec: '*',
6 silly cache add   type: 'range' }
7 verbose addNamed http-server@*
8 silly addNamed semver.valid null
9 silly addNamed semver.validRange *
10 silly addNameRange { name: 'http-server', range: '*', hasData: false }
11 silly mapToRegistry name http-server
12 silly mapToRegistry using default registry
13 silly mapToRegistry registry https://registry.npmjs.org/
14 silly mapToRegistry uri https://registry.npmjs.org/http-server
15 verbose addNameRange registry:https://registry.npmjs.org/http-server not in flight; fetching
16 verbose request uri https://registry.npmjs.org/http-server
17 verbose request no auth needed
18 info attempt registry request try #1 at 13:19:49
19 verbose request id ded304ef8a375eb0
20 verbose etag "49E8TO09NC75K07BOJVRPOK44"
21 http request GET https://registry.npmjs.org/http-server
22 http 304 https://registry.npmjs.org/http-server
23 silly get cb [ 304,
23 silly get   { date: 'Mon, 11 May 2015 05:19:52 GMT',
23 silly get     via: '1.1 varnish',
23 silly get     'cache-control': 'max-age=60',
23 silly get     etag: '"49E8TO09NC75K07BOJVRPOK44"',
23 silly get     age: '0',
23 silly get     connection: 'keep-alive',
23 silly get     'x-served-by': 'cache-nrt6127-NRT',
23 silly get     'x-cache': 'HIT',
23 silly get     'x-cache-hits': '1',
23 silly get     'x-timer': 'S1431321592.180557,VS0,VE167',
23 silly get     vary: 'Accept' } ]
24 verbose etag https://registry.npmjs.org/http-server from cache
25 verbose get saving http-server to /Users/wfp/.npm/registry.npmjs.org/http-server/.cache.json
26 silly addNameRange number 2 { name: 'http-server', range: '*', hasData: true }
27 silly addNameRange versions [ 'http-server',
27 silly addNameRange   [ '0.1.0',
27 silly addNameRange     '0.1.1',
27 silly addNameRange     '0.1.3',
27 silly addNameRange     '0.2.1',
27 silly addNameRange     '0.2.2',
27 silly addNameRange     '0.2.3',
27 silly addNameRange     '0.2.4',
27 silly addNameRange     '0.2.5',
27 silly addNameRange     '0.2.6',
27 silly addNameRange     '0.2.9',
27 silly addNameRange     '0.3.0',
27 silly addNameRange     '0.4.0',
27 silly addNameRange     '0.4.1',
27 silly addNameRange     '0.5.0',
27 silly addNameRange     '0.5.1',
27 silly addNameRange     '0.5.2',
27 silly addNameRange     '0.5.3',
27 silly addNameRange     '0.5.5',
27 silly addNameRange     '0.6.0',
27 silly addNameRange     '0.6.1',
27 silly addNameRange     '0.7.0',
27 silly addNameRange     '0.7.1',
27 silly addNameRange     '0.7.2',
27 silly addNameRange     '0.7.3',
27 silly addNameRange     '0.7.4',
27 silly addNameRange     '0.7.5',
27 silly addNameRange     '0.8.0' ] ]
28 verbose addNamed http-server@0.8.0
29 silly addNamed semver.valid 0.8.0
30 silly addNamed semver.validRange 0.8.0
31 silly cache afterAdd http-server@0.8.0
32 verbose afterAdd /Users/wfp/.npm/http-server/0.8.0/package/package.json not in flight; writing
33 verbose afterAdd /Users/wfp/.npm/http-server/0.8.0/package/package.json written
34 silly install resolved [ { name: 'http-server',
34 silly install resolved     version: '0.8.0',
34 silly install resolved     description: 'A simple zero-configuration command-line http server',
34 silly install resolved     main: './lib/http-server',
34 silly install resolved     repository:
34 silly install resolved      { type: 'git',
34 silly install resolved        url: 'git://github.com/indexzero/http-server.git' },
34 silly install resolved     keywords: [ 'cli', 'command' ],
34 silly install resolved     scripts:
34 silly install resolved      { start: 'node ./bin/http-server',
34 silly install resolved        pretest: 'stylezero bin/ lib/ test',
34 silly install resolved        test: 'vows --spec --isolate' },
34 silly install resolved     contributors:
34 silly install resolved      [ [Object],
34 silly install resolved        [Object],
34 silly install resolved        [Object],
34 silly install resolved        [Object],
34 silly install resolved        [Object],
34 silly install resolved        [Object],
34 silly install resolved        [Object],
34 silly install resolved        [Object],
34 silly install resolved        [Object],
34 silly install resolved        [Object] ],
34 silly install resolved     dependencies:
34 silly install resolved      { colors: '1.0.3',
34 silly install resolved        optimist: '0.6.x',
34 silly install resolved        union: '~0.4.3',
34 silly install resolved        ecstatic: '~0.7.0',
34 silly install resolved        'http-proxy': '^1.8.1',
34 silly install resolved        portfinder: '0.4.x',
34 silly install resolved        opener: '~1.4.0',
34 silly install resolved        corser: '~2.0.0' },
34 silly install resolved     devDependencies: { vows: '0.7.x', request: '2.49.x', stylezero: '2.2.0' },
34 silly install resolved     bugs: { url: 'https://github.com/nodeapps/http-server/issues' },
34 silly install resolved     licenses: [ [Object] ],
34 silly install resolved     preferGlobal: 'true',
34 silly install resolved     bin: { 'http-server': './bin/http-server', hs: './bin/http-server' },
34 silly install resolved     gitHead: 'ac38a041c954c863fd695b0f70ba251399856812',
34 silly install resolved     homepage: 'https://github.com/indexzero/http-server',
34 silly install resolved     _id: 'http-server@0.8.0',
34 silly install resolved     _shasum: 'd4b671781ec6bf9fa6a311cd1df683b0b37b1491',
34 silly install resolved     _from: 'http-server@*',
34 silly install resolved     _npmVersion: '2.2.0',
34 silly install resolved     _nodeVersion: '0.10.33',
34 silly install resolved     _npmUser: { name: 'indexzero', email: 'charlie.robbins@gmail.com' },
34 silly install resolved     maintainers: [ [Object] ],
34 silly install resolved     dist:
34 silly install resolved      { shasum: 'd4b671781ec6bf9fa6a311cd1df683b0b37b1491',
34 silly install resolved        tarball: 'http://registry.npmjs.org/http-server/-/http-server-0.8.0.tgz' },
34 silly install resolved     directories: {},
34 silly install resolved     _resolved: 'https://registry.npmjs.org/http-server/-/http-server-0.8.0.tgz',
34 silly install resolved     readme: 'ERROR: No README data found!' } ]
35 info install http-server@0.8.0 into /usr/local/lib
36 info installOne http-server@0.8.0
37 verbose installOne of http-server to /usr/local/lib not in flight; installing
38 verbose lock using /Users/wfp/.npm/_locks/http-server-ae30c9ae1f4c5eaa.lock for /usr/local/lib/node_modules/http-server
39 silly install write writing http-server 0.8.0 to /usr/local/lib/node_modules/http-server
40 silly cache addNamed cb http-server@0.8.0
41 verbose unbuild lib/node_modules/http-server
42 silly gentlyRm /usr/local/lib/node_modules/http-server is being purged from base /usr/local
43 verbose gentlyRm don't care about contents; nuking /usr/local/lib/node_modules/http-server
44 verbose tar unpack /Users/wfp/.npm/http-server/0.8.0/package.tgz
45 verbose tar unpacking to /usr/local/lib/node_modules/http-server
46 silly gentlyRm /usr/local/lib/node_modules/http-server is being purged
47 verbose gentlyRm don't care about contents; nuking /usr/local/lib/node_modules/http-server
48 silly gunzTarPerm modes [ '755', '644' ]
49 error tar.unpack untar error /Users/wfp/.npm/http-server/0.8.0/package.tgz
50 verbose unlock done using /Users/wfp/.npm/_locks/http-server-ae30c9ae1f4c5eaa.lock for /usr/local/lib/node_modules/http-server
51 verbose fstream_path /usr/local/lib/node_modules/http-server
52 verbose fstream_type Directory
53 verbose fstream_class DirWriter
54 verbose stack Error: EACCES, mkdir '/usr/local/lib/node_modules/http-server'
54 verbose stack     at Error (native)
55 verbose fstream_stack /usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23
55 verbose fstream_stack /usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:46:53
55 verbose fstream_stack FSReqWrap.oncomplete (fs.js:95:15)
56 verbose cwd /Users/wfp
57 error Darwin 14.1.1
58 error argv "node" "/usr/local/bin/npm" "install" "http-server" "-g"
59 error node v0.12.2
60 error npm  v2.7.4
61 error path /usr/local/lib/node_modules/http-server
62 error code EACCES
63 error errno -13
64 error Error: EACCES, mkdir '/usr/local/lib/node_modules/http-server'
64 error     at Error (native)
64 error  { [Error: EACCES, mkdir '/usr/local/lib/node_modules/http-server']
64 error   errno: -13,
64 error   code: 'EACCES',
64 error   path: '/usr/local/lib/node_modules/http-server',
64 error   fstream_type: 'Directory',
64 error   fstream_path: '/usr/local/lib/node_modules/http-server',
64 error   fstream_class: 'DirWriter',
64 error   fstream_stack:
64 error    [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23',
64 error      '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:46:53',
64 error      'FSReqWrap.oncomplete (fs.js:95:15)' ] }
65 error Please try running this command again as root/Administrator.
66 verbose exit [ -13, true ]
67 verbose unbuild lib/node_modules/http-server
68 silly gentlyRm /usr/local/lib/node_modules/http-server is being purged from base /usr/local
69 verbose gentlyRm don't care about contents; nuking /usr/local/lib/node_modules/http-server

谁能帮我分析一下,到底是哪里出错了?

PHPz
PHPz

学习是最好的投资!

reply all(1)
Peter_Zhu

I found the answer, I have to use the sudo command

sudo npm install http-server -g

Everything with "-g" (global installation) must use the sudo command and enter a password.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template