ubuntu - gulp -v 安装后报错

标签 ubuntu npm gulp

我正在尝试在我的 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

最佳答案

您的 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版本,但这个应该工作。

关于ubuntu - gulp -v 安装后报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23308077/

相关文章:

javascript - NodeJS 示例应用无法启动,无法找到 'config'?

用于构建/测试与部署的 Node.js 项目布局

java - 更改 java 安装的选择和状态

Dockerfile : add npm to an existing docker image

node.js - gulp 在安装 semantic-ui 时找不到 semantic.json

javascript - 安装Gulp js时出现错误

javascript - 定义了两个自调用匿名函数导致错误

ruby-on-rails - rails 3生成 Controller 不起作用

MYSQL 根访问被拒绝(密码重置不起作用)

bash - 从终端和 bash 脚本回显 PROMPT_COMMAND