我正试图在我的Vagrant机器(Ubuntu盒子)上使用gulp,因此安装它是这样的:
sudo apt-get install nodejs npm
sudo npm install -g gulp
但是在尝试gulp -v时我得到了这个:
vagrant@laravel:/var/www$ gulp -v
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module 'optimist'
at Function._resolveFilename (module.js:332:11)
at Function._load (module.js:279:25)
at Module.require (module.js:354:17)
at require (module.js:370:17)
at Object.<anonymous> (/usr/local/lib/node_modules/gulp/bin/gulp:4:10)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:32)
at Function._load (module.js:308:12)
at Array.0 (module.js:479:10)
at EventEmitter._tickCallback (node.js:192:41)
所以我另外跑了sudo npm install -g optimist
。上面的错误已经解决了,但现在我坚持这个:
vagrant@laravel:/var/www$ gulp -v
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: undefined is not a function
at /usr/local/lib/node_modules/gulp/bin/gulp:26:12
at Array.filter (native)
at getGulpFile (/usr/local/lib/node_modules/gulp/bin/gulp:25:6)
at Object.<anonymous> (/usr/local/lib/node_modules/gulp/bin/gulp:8:18)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:32)
at Function._load (module.js:308:12)
at Array.0 (module.js:479:10)
at EventEmitter._tickCallback (node.js:192:41)
有什么想法吗?谢谢!
PS。这些是运行的版本:
vagrant@laravel:/var/www$ node -v
v0.6.12
vagrant@laravel:/var/www$ npm -v
1.1.4
答案 0 :(得分:1)
您的NodeJS
版本太旧了。这很可能就是问题,Gulp
似乎只在>= 0.9
上运行。
这是由于apt-get
软件包已过时,您可以使用此Vagrant脚本获取最新版本:
config.vm.provision :shell, inline: "sudo add-apt-repository ppa:chris-lea/node.js"
config.vm.provision :shell, inline: "sudo apt-get update"
config.vm.provision :shell, inline: "sudo apt-get install -y nodejs --no-install-recommends"
A example of a working Vagrant file with the newest node can be found here.
还有其他方法可以获得最新的Node
版本,但这个版本应该有效。