【问题标题】:gulp is not working correctly, version doesn't showgulp 工作不正常,版本不显示
【发布时间】:2016-01-07 11:49:07
【问题描述】:

从事一个项目,我决定使用 gulp 进行 Typescript 观察和转译。

这是我安装所有东西的步骤。

这一切都是在我项目的根目录中完成的:

$ sudo npm update
$ npm -v #1.3.10
$ npm init #to create the package.json
$ sudo npm install gulp -g #installing gulp globally
$ gulp -v # No version number is shown.. why?
$ npm install gulp --save-dev
$ npm install gulp-typescript
$ vim gulpfile.js

这是我的 gulpfile.js 的内容:

var gulp = require('gulp');
var ts = require('gulp-typescript');

var tsProject = ts.createProject({
    declaration: true,
    noExternalResolve: true
});

gulp.task('scripts', function() {
    return gulp.src('web/ts/*.ts')
                    .pipe(ts(tsProject))
                    .pipe(gulp.dest('web/js'))
});
gulp.task('watch', ['scripts'], function() {
    gulp.watch('web/ts/*.ts', ['scripts']);
});

但是,当我运行 $ gulp scripts 时,我什么也没得到。没有错误。我做错了什么?

gulp-typescript

【问题讨论】:

  • 你为什么用sudo安装gulp?这意味着您每次都必须以 root 身份运行 gulp
  • @br3w5 我需要全局安装 gulp 的权限,不是吗?当我尝试在不使用 sudo 的情况下全局安装 gulp 时,我收到了一个漂亮的错误。
  • 是的,但看起来您还使用 sudo 安装了节点,对吗?所以除非你是 root 否则你将无法运行 npm
  • 您的 npm 已经很旧了(请参阅此处的版本 github.com/npm/npm/releases)您可以通过这种方式更新您的 npm:stackoverflow.com/questions/6237295/…

标签: ubuntu npm typescript gulp


【解决方案1】:

在 MartylX 发表评论后,我开始检查我的 npm 和 node 版本,它们显然不是最新的.. 看到我最近安装了它们,我觉得这很尴尬。

我决定完全重新安装所有东西。

$ sudo apt-get remove node
$ sudo apt-get remove nodejs
$ sudo apt-get remove npm

我决定安装NVM:

$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.29.0/install.sh | bash

我安装了最新版本的节点:

$ nvm install stable
$ node -v #v4.1.2

然后我重新安装了 npm:

$ sudo apt-get install npm

然后我更新了它:

$ sudo npm update -g npm
$ npm -v #2.14.4

然后我在全局(以及我的项目的根目录)安装了 gulp:

$ sudo npm install -g gulp
$ npm install gulp --save-dev #make sure you did an npm init if you haven't yet
$ gulp #errors are now shown!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-18
    • 2019-02-09
    • 2021-09-22
    • 1970-01-01
    • 1970-01-01
    • 2016-10-06
    • 1970-01-01
    相关资源
    最近更新 更多