这是什么意思:TypeError:dest.on不是函数

问题描述 投票:0回答:1

我是一个新手,遵循关于现代webdev工作流程的教程。我在控制台中收到此错误消息。 TypeError: dest.on is not a function我知道,这里有相关的问题和答案。但我不明白他们。因为我不知道“dest.on”与什么有关,它做了什么。这是到目前为止的代码:

var gulp = require("gulp");
var sass = require("gulp-sass");
var sourcemaps = require("gulp-sourcemaps");
var autoprefixer = require("auto-prefixer");
var imagemin = require("gulp-imagemin");
var browserSync = require("browser-sync").create();

gulp.task("css", function() {
  return gulp
    .src("src/sass/**/*.scss")
    .pipe(sourcemaps.init())
    .pipe(sass({ outputStyle: "compressed" }).on("error", sass.logError))
    .pipe(
      autoprefixer({
        browsers: ["last 2 versions"]
      })
    )
    .pipe(sourcemaps.write("./maps"))
    .pipe(gulp.dest("dist/css"));
});

任何人都可以解释一下,错误信息是什么意思以及如何解决这个特殊问题?我很抱歉冗余,但我找不到现有答案的解决方案。

编辑::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::::也许它有助于添加package.json

{
  "name": "sitepointresponsivewebsite",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "auto-prefixer": "^0.4.2",
    "browser-sync": "^2.26.3",
    "gulp": "^4.0.0",
    "gulp-imagemin": "^5.0.3",
    "gulp-sass": "^4.0.2",
    "gulp-sourcemaps": "^2.6.5"
  }
}

这是完整的终端错误消息

`

Beratungs-MacBook-Pro-2:sitepointResponsiveWebsite Beratung1$ gulp css
[14:04:02] Using gulpfile ~/Desktop/sitepointResponsiveWebsite/gulpfile.js
[14:04:02] Starting 'css'...
[14:04:02] 'css' errored after 12 ms
[14:04:02] TypeError: dest.on is not a function
    at DestroyableTransform.Readable.pipe (/Users/Beratung1/Desktop/sitepointResponsiveWebsite/node_modules/readable-stream/lib/_stream_readable.js:564:8)
    at /Users/Beratung1/Desktop/sitepointResponsiveWebsite/gulpfile.js:13:6
    at taskWrapper (/Users/Beratung1/Desktop/sitepointResponsiveWebsite/node_modules/undertaker/lib/set-task.js:13:15)
    at bound (domain.js:396:14)
    at runBound (domain.js:409:12)
    at asyncRunner (/Users/Beratung1/Desktop/sitepointResponsiveWebsite/node_modules/async-done/index.js:55:18)
    at process._tickCallback (internal/process/next_tick.js:61:11)
javascript gulp
1个回答
2
投票

对于像这样的不熟悉的错误消息,堆栈跟踪通常是最有帮助的。

at DestroyableTransform.Readable.pipe (/Users/Beratung1/Desktop/sitepointResponsiveWebsite/node_modules/readable-stream/lib/_stream_readable.js:564:8)
at /Users/Beratung1/Desktop/sitepointResponsiveWebsite/gulpfile.js:13:6

错误发生在可读流中的pipe()方法中。 destpipe()的第一个参数的名称; “dest.on”不存在的事实意味着你传递给pipe()的东西实际上并不是一个流。

第二个堆栈帧指的是第13行,这是这个pipe()调用:

.pipe(
  autoprefixer({
    browsers: ["last 2 versions"]
  })
)

因此,autoprefixer()的返回值不是流。

autoprefixer是:

var autoprefixer = require("auto-prefixer");

在npm上查看该模块:https://www.npmjs.com/package/auto-prefixer。看起来很奇怪,它绝对不是一个流API。

真正的autoprefixer模块被称为autoprefixer,没有破折号。您可以将它与gulp-postcss一起使用,如下所述:https://www.npmjs.com/package/autoprefixer#gulp

var postcss = require('gulp-postcss')
var autoprefixer = require('autoprefixer')

// .. etc ..
  .pipe(postcss([ autoprefixer({
    // .. options ..
  }) ]))
© www.soinside.com 2019 - 2024. All rights reserved.