有人能帮忙吗?我不断地收到这个错误,我真的不知道还能做些什么。当我在cmd中触发命令gulp watch时,我收到以下错误TypeError: Cannot read property 'watch' of undefined
C:\Apache24\htdocs\Gulp>gulp手表10:37:07使用C:\Apache24\htdocs\Gulp\gulpfile.js 10:37:07开始“手表”10:37:07‘手表’在4.16毫秒10:37:07后出现错误,TypeError:无法读取未定义的手表(C:\Apache24\htdocs\Gulp\gulpfile.js:42:10) at watch的属性(C:\Apache24\htdocs\Gulp\gulpfile.js:42:10)在runBound (domain.js:422:14) at runBound (domain.js:435:12) at asyncRunner (C:\Apache24 24\htdocs\)Gulp\node_modules\异步完成\index.js:55:18)在processTicksAndRejections (内部/process/task_Quees.js:75:11)
const {src, dest, series, gulp, parallel} = require('gulp');
var rename = require('gulp-rename');
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var sourcemaps = require('gulp-sourcemaps');
var styleSRC = './src/scss/style.scss';
var styleDIST = './dist/css/';
var jsSRC = './src/js/script.js';
var jsDIST = './dist/js/';
function style() {
"use strict";
return src(styleSRC)
.pipe(sourcemaps.init())
.pipe(sass({
errorLogToConsole: true,
outputStyle: 'compressed'
}))
.on('error', console.error.bind(console))
.pipe(autoprefixer({
overrideBrowserslist: ["defaults"],
cascade: false
}))
.pipe(rename({basename: 'style', suffix: '.min'}))
.pipe(sourcemaps.write('./'))
.pipe(dest(styleDIST));
}
function js() {
"use strict";
return src(jsSRC)
.pipe(dest(jsDIST));
}
const watch = function () {
"use strict";
gulp.watch('./src/scss/**/*.scss', {usePolling: true}, gulp.series(style));
gulp.watch('./src/js/**/*.js', {usePolling: true}, gulp.series(js));
};
exports.default = series(
parallel(style, js),
watch
);
exports.watch = watch;
exports.js = js;
exports.style = style;发布于 2019-11-28 10:39:59
我想你的破坏有点错了。你有:
const {src, dest, series, gulp, parallel} = require('gulp');
// ^ this does not exist - hence the undefined property我认为您想用watch替换销毁过程中的watch,所以现在是:
const {src, dest, series, watch, parallel} = require('gulp');在您的watch函数中,请执行:
// renamed the function to avoid conflict
const watchTask = function () {
"use strict";
watch('./src/scss/**/*.scss', {usePolling: true}, series(style));
watch('./src/js/**/*.js', {usePolling: true}, series(js));
};
exports.default = series(
parallel(style, js),
watchTask
);
exports.watch = watchTask;发布于 2019-11-28 09:58:31
尝试一下,删除const并将其定义为一个函数。
function watch() {
"use strict";
gulp.watch('./src/scss/**/*.scss', {usePolling: true}, gulp.series(style));
gulp.watch('./src/js/**/*.js', {usePolling: true}, gulp.series(js));
};https://stackoverflow.com/questions/59085999
复制相似问题