Skip to content

Compilation errors kill gulp watch: Error [ERR_STREAM_PUSH_AFTER_EOF]: stream.push() after EOF #569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AlexanderOMara opened this issue Mar 15, 2018 · 12 comments

Comments

@AlexanderOMara
Copy link

AlexanderOMara commented Mar 15, 2018

Expected behavior:

Expected that failed builds would not force gulp watch to shutdown.

Actual behavior:

Failed builds throw uncaught exceptions.

Your gulpfile:

gulpfile.babel.js (using Gulp 4)

import gulp from 'gulp';
import gulpTypescript from 'gulp-typescript';
import pumpPromise from 'pump-promise';


gulp.task('build', async function task() {
	const project = gulpTypescript.createProject('tsconfig.json', {
		declaration: true
	});
	const ts = project(gulpTypescript.reporter.fullReporter(true));

	await pumpPromise(
		gulp.src('index.ts'),
		ts
	);

	await pumpPromise(
		ts.js,
		gulp.dest('lib')
	);
	await pumpPromise(
		ts.dts,
		gulp.dest('lib')
	);
});

gulp.task('watch', async function() {
	gulp.watch('index.ts', {}, gulp.parallel('build'));
});

tsconfig.json

Include your tsconfig, if related to this issue.

{}

Here's a Gits to demonstrate the error

First run:

yarn install
yarn run gulp watch

Then edit index.ts and replace class Greeter with class GreeterBad and see:

[17:38:44] Starting 'build'...
[gulp-typescript] 2552 Cannot find name 'Greeter'. Did you mean 'greeter'?
> file: /projects/74a0da2e5b0b0625585743f2b9725a46/index.ts:
> [10] let greeter = new Greeter("world");
[gulp-typescript] 2552 Cannot find name 'Greeter'. Did you mean 'greeter'?
> file: /projects/74a0da2e5b0b0625585743f2b9725a46/index.ts:
> [10] let greeter = new Greeter("world");
TypeScript: 1 semantic error
TypeScript: emit succeeded (with errors)
[17:38:46] 'build' errored after 1.9 s
[17:38:46] Error [ERR_STREAM_PUSH_AFTER_EOF]: stream.push() after EOF
    at readableAddChunk (_stream_readable.js:246:30)
    at CompileOutputStream.Readable.push (_stream_readable.js:213:10)
    at Output.writeJs (/projects/74a0da2e5b0b0625585743f2b9725a46/node_modules/gulp-typescript/release/output.js:25:23)
    at ProjectCompiler.emitFile (/projects/74a0da2e5b0b0625585743f2b9725a46/node_modules/gulp-typescript/release/compiler.js:144:33)
    at ProjectCompiler.inputDone (/projects/74a0da2e5b0b0625585743f2b9725a46/node_modules/gulp-typescript/release/compiler.js:76:22)
    at CompileStream.end (/projects/74a0da2e5b0b0625585743f2b9725a46/node_modules/gulp-typescript/release/project.js:136:31)
    at DestroyableTransform.onend (/projects/74a0da2e5b0b0625585743f2b9725a46/node_modules/readable-stream/lib/_stream_readable.js:577:10)
    at Object.onceWrapper (events.js:255:19)
    at DestroyableTransform.emit (events.js:165:20)
    at endReadableNT (/projects/74a0da2e5b0b0625585743f2b9725a46/node_modules/readable-stream/lib/_stream_readable.js:1000:12)
events.js:137
      throw er; // Unhandled 'error' event
      ^

Error [ERR_STREAM_PUSH_AFTER_EOF]: stream.push() after EOF
    at readableAddChunk (_stream_readable.js:246:30)
    at CompileOutputStream.Readable.push (_stream_readable.js:213:10)
    at Output.writeDts (/projects/74a0da2e5b0b0625585743f2b9725a46/node_modules/gulp-typescript/release/output.js:35:24)
    at ProjectCompiler.emitFile (/projects/74a0da2e5b0b0625585743f2b9725a46/node_modules/gulp-typescript/release/compiler.js:147:33)
    at ProjectCompiler.inputDone (/projects/74a0da2e5b0b0625585743f2b9725a46/node_modules/gulp-typescript/release/compiler.js:76:22)
    at CompileStream.end (/projects/74a0da2e5b0b0625585743f2b9725a46/node_modules/gulp-typescript/release/project.js:136:31)
    at DestroyableTransform.onend (/projects/74a0da2e5b0b0625585743f2b9725a46/node_modules/readable-stream/lib/_stream_readable.js:577:10)
    at Object.onceWrapper (events.js:255:19)
    at DestroyableTransform.emit (events.js:165:20)
    at endReadableNT (/projects/74a0da2e5b0b0625585743f2b9725a46/node_modules/readable-stream/lib/_stream_readable.js:1000:12)
error An unexpected error occurred: "Command failed.
Exit code: 1

If a watch task fails, it shouldn't kill the watch, as that's a huge pain to restart every time it fails.

@AlexanderOMara
Copy link
Author

It's also kinda strange that I see the compiler error twice:

[gulp-typescript] 2552 Cannot find name 'Greeter'. Did you mean 'greeter'?
> file: /projects/74a0da2e5b0b0625585743f2b9725a46/index.ts:
> [10] let greeter = new Greeter("world");
[gulp-typescript] 2552 Cannot find name 'Greeter'. Did you mean 'greeter'?
> file: /projects/74a0da2e5b0b0625585743f2b9725a46/index.ts:
> [10] let greeter = new Greeter("world");

Not sure if that is related.

@ivogabe
Copy link
Owner

ivogabe commented Mar 15, 2018

I guess that it might be caused by the usage of pumpPromise. I use the normal pipe method on my projects, and the gulp process does not crash on compile error but keeps watching. Could you try to remove that from your config?

@AlexanderOMara
Copy link
Author

AlexanderOMara commented Mar 15, 2018

Hmm, that's strange. This does work (but with one issue):

gulp.task('build', async function task() {
	const project = gulpTypescript.createProject('tsconfig.json', {
		declaration: true
	});
	const ts = project(gulpTypescript.reporter.fullReporter(true));

	gulp.src('index.ts').pipe(ts);

	await pumpPromise(
		ts.js,
		gulp.dest('lib')
	);
	await pumpPromise(
		ts.dts,
		gulp.dest('lib')
	);
});

If I do that though, yarn run gulp build reports success even though it should have failed:

[18:47:59] Starting 'build'...
[gulp-typescript] 2552 Cannot find name 'Greeter'. Did you mean 'greeter'?
> file: /projects/74a0da2e5b0b0625585743f2b9725a46/index.ts:
> [10] let greeter = new Greeter("world");
TypeScript: 1 semantic error
TypeScript: emit succeeded (with errors)
[18:48:01] Finished 'build' after 1.21 s

Any idea how I can get it to fail properly without using pump-promise?

@ivogabe
Copy link
Owner

ivogabe commented Mar 15, 2018

Could you try to remove the other usages of pumpPromise?

@AlexanderOMara
Copy link
Author

Same deal with just this:

gulp.task('build', function task() {
	const project = gulpTypescript.createProject('tsconfig.json', {
		declaration: true
	});
	const ts = project(gulpTypescript.reporter.fullReporter(true));

	return gulp.src('index.ts').pipe(ts);
});

@ivogabe
Copy link
Owner

ivogabe commented Mar 15, 2018

After re-reading your previous post, it seems that that behavior is correct. It says that it had one error, that the code generation succeeded, and finally that the task finished. Note that TypeScript can still generate JavaScript code, even when there are type errors. If you don't want that, you should set noEmitOnError: true.

@AlexanderOMara
Copy link
Author

Makes sense I guess, but this makes things even stranger:

gulp.task('build', function task() {
	const project = gulpTypescript.createProject('tsconfig.json', {
		declaration: true,
		noEmitOnError: true
	});
	const ts = project(gulpTypescript.reporter.fullReporter(true));

	return gulp.src('index.ts').pipe(ts);
});
$ yarn run gulp build
yarn run v1.5.1
$ /projects/74a0da2e5b0b0625585743f2b9725a46/node_modules/.bin/gulp build
[19:03:18] Requiring external module @babel/register
[19:03:18] Using gulpfile /projects/74a0da2e5b0b0625585743f2b9725a46/gulpfile.babel.js
[19:03:18] Starting 'build'...
[gulp-typescript] 2552 Cannot find name 'Greeter'. Did you mean 'greeter'?
> file: /projects/74a0da2e5b0b0625585743f2b9725a46/index.ts:
> [10] let greeter = new Greeter("world");
[gulp-typescript] 2552 Cannot find name 'Greeter'. Did you mean 'greeter'?
> file: /projects/74a0da2e5b0b0625585743f2b9725a46/index.ts:
> [10] let greeter = new Greeter("world");
TypeScript: 1 semantic error
TypeScript: 1 emit error
TypeScript: emit failed
[19:03:19] Finished 'build' after 1.11 s
✨  Done in 1.98s.

It reports success, and also reports the same error twice.

@ivogabe
Copy link
Owner

ivogabe commented Mar 15, 2018

The duplicate error is tracked by #543. It does not report success, it just shows that the task is finished. That message is also controlled by gulp and not by gulp-typescript.

@AlexanderOMara
Copy link
Author

Failed tasks should show this in gulp's output:

[19:09:08] Starting 'fail'...
[19:09:08] 'fail' errored after 2.12 ms
[19:09:08] Error: test
    at task (/projects/74a0da2e5b0b0625585743f2b9725a46/gulpfile.babel.js:59:8)
    at taskWrapper (/projects/74a0da2e5b0b0625585743f2b9725a46/node_modules/undertaker/lib/set-task.js:13:15)
    at bound (domain.js:370:14)
    at runBound (domain.js:383:12)
    at asyncRunner (/projects/74a0da2e5b0b0625585743f2b9725a46/node_modules/async-done/index.js:55:18)
    at process._tickCallback (internal/process/next_tick.js:150:11)
error An unexpected error occurred: "Command failed.
Exit code: 1

Example failing task:

gulp.task('fail', async function task() {
	throw new Error('test');
});

@ivogabe
Copy link
Owner

ivogabe commented Mar 15, 2018

Sadly that doesn't work with streams, as streams in NodeJS break when one part errors. This would cause that the whole watch process crashes.

@AlexanderOMara
Copy link
Author

Yeah, I know. It's a pain. That's what pump-promise is supposed to solve, but not in this case for some reason.

I guess I'll have to work around it by writing the event listeners manually.

Otherwise the exit code will report success, and use with a CI is very difficult.

@ivogabe
Copy link
Owner

ivogabe commented Jun 11, 2018

The crashing on errors and exit code has changed in the latest alpha release (5.0.0-alpha.1), see #295. I'm afraid that we can't solve the problems with pumpPromise, so I'll close this issue.

@ivogabe ivogabe closed this as completed Jun 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants