I'm getting an error when I watch for changes in index.html
(full path in CONFIG.APP.INDEX
). All my tasks are in separate files. this is tasks/watch.ts, for example:
import * as CONFIG from '../config';
export default done => {
// other watches
gulp.watch(CONFIG.APP.INDEX, gulp.series('inject'));
};
on first change task is executed normally, but on second change I'm getting this error:
c:\~\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:203
var er = new Error('write after end');
^
Error: write after end
at writeAfterEnd (c:\~\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:203:12)
at DestroyableTransform.Writable.write (c:\~\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:239:20)
at DestroyableTransform.ondata (c:\~\node_modules\through2\node_modules\readable-stream\lib\_stream_readable.js:531:20)
at emitOne (events.js:77:13)
at DestroyableTransform.emit (events.js:169:7)
at readableAddChunk (c:\~\node_modules\through2\node_modules\readable-stream\lib\_stream_readable.js:198:18)
at DestroyableTransform.Readable.push (c:\~\node_modules\through2\node_modules\readable-stream\lib\_stream_readable.js:157:10)
at DestroyableTransform.Transform.push (c:\~\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:123:32)
at afterTransform (c:\~\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:79:51)
at TransformState.afterTransform (c:\~\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:58:12)
at c:\~\node_modules\vinyl-fs\lib\src\getContents\bufferFile.js:18:5
at c:\~\node_modules\graceful-fs\graceful-fs.js:78:16
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:404:3)
tasks/inject.ts task:
declare var require;
const gulp = require('gulp');
const plugins = require('gulp-load-plugins')();
import * as CONFIG from '../config';
export default done => {
return gulp
.src(CONFIG.APP.INDEX)
.pipe(require('../util/inject/fixes').default) // <--- PROBLEM IS HERE
// other stuff...
.pipe(gulp.dest(CONFIG.DST.BUILD))
.on('error', plugins.util.log);
};
util/inject/fixes.ts task
declare var require;
const plugins = require('gulp-load-plugins')();
// errors even with this...
export default plugins.util.noop();
Tasks are loaded from gulpfile.ts/index.ts
like this:
fs.readdirSync('./gulpfile.ts/tasks').map(file => {
let name = file.replace(/\.ts$/, '');
let task = require(path.join(path.resolve('.'), 'gulpfile.ts', 'tasks', file));
gulp.task(name, task.default);
});
I've managed to identify where the error comes from, but no idea what's causing it, or how to fix it. Problem only occurs when watching index.html
after first change and task execution. Running task manually works normally (gulp inject
), and all other watches and tasks work normally.