Karma Phantomjs安装错误

时间:2016-04-02 13:09:52

标签: angularjs karma-jasmine

我是Angularjs的新手,并尝试使用单元测试进行测试。但我有问题通过此命令安装karma和phantomjs。

npm install karma-cli phantomjs -g

并面临此错误

 deprecated phantomjs@2.1.3: Package renamed to phantomjs-prebuilt. Please update 'phantomjs' package references to 'phantomjs-prebuilt'
npm ERR! Error: EACCES, mkdir '/usr/lib/node_modules/phantomjs'
npm ERR!  { [Error: EACCES, mkdir '/usr/lib/node_modules/phantomjs']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/usr/lib/node_modules/phantomjs',
npm ERR!   fstream_type: 'Directory',
npm ERR!   fstream_path: '/usr/lib/node_modules/phantomjs',
npm ERR!   fstream_class: 'DirWriter',
npm ERR!   fstream_stack: 
npm ERR!    [ '/usr/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23',
npm ERR!      '/usr/lib/node_modules/npm/node_modules/mkdirp/index.js:46:53',
npm ERR!      'Object.oncomplete (fs.js:108:15)' ] }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

然后我使用这个cammand

npm install karma-cli phantomjs-prebuilt -g

然后发生此错误

 Error: EACCES, mkdir '/usr/lib/node_modules/phantomjs-prebuilt'
npm ERR!  { [Error: EACCES, mkdir '/usr/lib/node_modules/phantomjs-prebuilt']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/usr/lib/node_modules/phantomjs-prebuilt',
npm ERR!   fstream_type: 'Directory',
npm ERR!   fstream_path: '/usr/lib/node_modules/phantomjs-prebuilt',
npm ERR!   fstream_class: 'DirWriter',
npm ERR!   fstream_stack: 
npm ERR!    [ '/usr/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23',
npm ERR!      '/usr/lib/node_modules/npm/node_modules/mkdirp/index.js:46:53',
npm ERR!      'Object.oncomplete (fs.js:108:15)' ] }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

所以请帮我解决这个问题。

1 个答案:

答案 0 :(得分:0)

这似乎是一个简单的特权问题。你'好像正在运行这个命令作为"普通用户"并且,当您全局安装时,目标路径似乎只能由root

写入

可以使用' sudo'

轻松解决
sudo npm install karma-cli phantomjs -g

sudo npm install karma-cli phantomjs-prebuilt -g