我是新手,紧跟有关现代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)
答案 0 :(得分: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()
方法中。 dest
是pipe()
的第一个参数的名称; “ 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。
real 自动前缀程序模块称为autoprefixer
,不带破折号。您可以将其与gulp-postcss一起使用,如此处所述:https://www.npmjs.com/package/autoprefixer#gulp
var postcss = require('gulp-postcss')
var autoprefixer = require('autoprefixer')
// .. etc ..
.pipe(postcss([ autoprefixer({
// .. options ..
}) ]))