如何通过npm在vagrant box上修复全局grunt错误

时间:2016-05-17 16:53:34

标签: npm gruntjs vagrant

我正在尝试在vagrantbox上设置开发环境 我的主机环境是:

  • windows 7
  • Vagrant版本1.8.1
  • Vbox版本5.0.20r106931

这是我的Vagrant文​​件:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|

  config.vm.box = "hashicorp/precise64"
  config.vm.hostname = "frontend"

  config.vm.provision "shell", path: "provision.sh"

  config.vm.provider "virtualbox" do |vb|
    # Display the VirtualBox GUI when booting the machine
    vb.gui = true

    # Customize the amount of memory on the VM:
    vb.memory = "4096"
    vb.cpus = "2"
  end

end

这是我的流浪汉配置文件:

apt-get -y update
apt-get -y install curl
apt-get -y install git
apt-get -y install nodejs
apt-get -y install npm
apt-get -y install python-pip

启动vagrant并在命令失败后进入ssh-ing:

sudo npm install -g grunt

这是来自npm-debug.log文件的错误日志:

info it worked if it ends with ok
verbose cli [ 'node', '/usr/bin/npm', 'install', '-g', 'grunt' ]
info using npm@1.1.4
info using node@v0.6.12
verbose config file /home/vagrant/.npmrc
verbose config file /usr/etc/npmrc
verbose config file /usr/share/npm/npmrc
silly exec /usr/bin/node "/usr/share/npm/bin/npm-get-uid-gid.js" "nobody" 1000
silly spawning [ '/usr/bin/node',
silly spawning   [ '/usr/share/npm/bin/npm-get-uid-gid.js', 'nobody', 1000 ],
silly spawning   null ]
silly output from getuid/gid {"uid":65534,"gid":1000}
silly output from getuid/gid 
verbose cache add [ 'grunt', null ]
silly cache add: name, spec, args [ undefined, 'grunt', [ 'grunt', null ] ]
verbose parsed url { pathname: 'grunt', path: 'grunt', href: 'grunt' }
verbose addNamed [ 'grunt', '' ]
verbose addNamed [ null, '' ]
silly name, range, hasData [ 'grunt', '', false ]
verbose raw, before any munging grunt
verbose url resolving [ 'https://registry.npmjs.org/', './grunt' ]
verbose url resolved https://registry.npmjs.org/grunt
http GET https://registry.npmjs.org/grunt
ERR! Error: failed to fetch from registry: grunt
ERR!     at /usr/share/npm/lib/utils/npm-registry-client/get.js:139:12
ERR!     at cb (/usr/share/npm/lib/utils/npm-registry-client/request.js:31:9)
ERR!     at Request._callback (/usr/share/npm/lib/utils/npm-registry-client/request.js:136:18)
ERR!     at Request.callback (/usr/lib/nodejs/request/main.js:119:22)
ERR!     at Request.<anonymous> (/usr/lib/nodejs/request/main.js:212:58)
ERR!     at Request.emit (events.js:88:20)
ERR!     at ClientRequest.<anonymous> (/usr/lib/nodejs/request/main.js:412:12)
ERR!     at ClientRequest.emit (events.js:67:17)
ERR!     at HTTPParser.onIncoming (http.js:1261:11)
ERR!     at HTTPParser.onHeadersComplete (http.js:102:31)
ERR! You may report this log at:
ERR!     <http://bugs.debian.org/npm>
ERR! or use
ERR!     reportbug --attach /vagrant/code/npm-debug.log npm
ERR! 
ERR! System Linux 3.2.0-23-generic
ERR! command "node" "/usr/bin/npm" "install" "-g" "grunt"
ERR! cwd /vagrant/code
ERR! node -v v0.6.12
ERR! npm -v 1.1.4
ERR! message failed to fetch from registry: grunt
verbose exit [ 1, true ]

1 个答案:

答案 0 :(得分:1)

即使精确尚未结束,你应该使用更新的ubuntu发布日期 - 你的盒子带有wily或xenial并且repo将是最新的

你有

info using npm@1.1.4
info using node@v0.6.12

但Grunt需要Node&gt; 0.8

所以:

  1. 更新您的信箱并使用最新版本
  2. 升级当前框中的node / nom版本