gpt4 book ai didi

javascript - 这是什么意思 : TypeError: dest. on is not a function

转载 作者:行者123 更新时间:2023-12-01 15:59:58 37 4
gpt4 key购买 nike

我是一个新手,正在学习有关现代 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)

最佳答案

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

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 ,没有破折号。您可以将它与 gulp-postcss 一起使用,如下所述: https://www.npmjs.com/package/autoprefixer#gulp
var postcss = require('gulp-postcss')
var autoprefixer = require('autoprefixer')

// .. etc ..
.pipe(postcss([ autoprefixer({
// .. options ..
}) ]))

关于javascript - 这是什么意思 : TypeError: dest. on is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55547794/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com