ubuntu - TypeError : gulp. 运行不是函数

标签 ubuntu gulp

我计划备份/镜像我的 linux 主目录中的所有文件。
首先我在这里读到:Skip local installation of Gulp
我在我的 Linux 主目录中安装了所有内容:

sudo apt install npm
sudo npm install --global gulp-cli
npm link gulp
npm init
$ gulp
[07:32:43] Using gulpfile ~/gulpfile.js
[07:32:43] Starting 'default'...
[07:32:43] Finished 'default' after 1.24 ms
如果发生更改,它会启动、等待并在每次发生错误时发送:
类型错误:gulp.run 不是函数
var gulp = require('gulp');
gulp.task('backupHomeDir', function () {
    return gulp.src('./*.js') // read all of the files that are in js with a .js extension
      // .pipe(gulp.dest('dist/js')); // write to the dist/js file
      .pipe(gulp.dest('/media/m/sdd2 ntfs/backup/home/'));
});
gulp.task('default', function () {
  // watch for changes
  gulp.watch('./*.js', function () {
      gulp.run('backupHomeDir');
    });
  });
我可以开始
$ sudo gulp
或者
$ gulp
错误是一样的:
[12:32:19] Using gulpfile /home/m/gulpfile.js
[12:32:19] Starting 'default'...
[12:33:09] Starting '<anonymous>'...
[12:33:09] '<anonymous>' errored after 1.08 ms
[12:33:09] TypeError: gulp.run is not a function
    at /home/m/gulpfile.js:22:12
    at bound (domain.js:402:14)
    at runBound (domain.js:415:12)
    at asyncRunner (/usr/local/lib/node_modules/gulp/node_modules/async-done/index.js:55:18)
    at process._tickCallback (internal/process/next_tick.js:61:11)
```

最佳答案

第一次重制npm i .
第二个 gulp.run 已弃用,您只需使用 gulp.watch()并将任务数组设置为第二个参数而不是回调,在您的情况下:

gulp.watch('./*.js', ['default','backupHomeDir']);
完全的:
var gulp = require('gulp');
gulp.task('default', function () {
  return gulp.src('./*.js') // read all
    .pipe(gulp.dest('/media/m/sdd2 ntfs/backup/home/'));
});
gulp.watch('./*.js', gulp.series('default'));

关于ubuntu - TypeError : gulp. 运行不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64087553/

相关文章:

javascript - Gulp Dest() 不输出文件

gulp - 在 vscode 中,由带有 isWatching 的任务生成的错误在修复后并不总是清除

msbuild - 事件顺序 - MSBuild 和任务运行器绑定(bind) (Gulp)

linux - 从哪里获得 gedit 主题

node.js - 无法在 Ubuntu 中使用 Node 包管理器安装包

ubuntu - 在 Ubuntu 15.10 上卸载 Netbeans 8.1

javascript - 在没有 bundler 的情况下使用 Vue?

css - 为什么这个 Gulp 片段中有多个 gulp.dest() ?

linux - 未找到 'modules.conf',不会加载任何模块

git - 这样的工具有什么问题: texlive-latex-base texlive-latex-recommended latex-xcolor pgf latex-beamer prosper texlive tipa?