LukeMc92 / flawless-sneakers

eCommerce store
0 stars 0 forks source link

Did you forget to signal async completion #1

Open LukeMc92 opened 4 years ago

LukeMc92 commented 4 years ago

Hi all,

I am getting this error message and I can't figure out what have gone wrong could any one point me in the right direction to get this fixed thanks please see below for the full error message.

[14:24:26] '' errored after 1.23 min [14:24:26] Error: exited with error code: 2 at ChildProcess.onexit (C:\Users\Luke McNally\Desktop\projects\flawless-sneakers\node_modules\end-of-stream\index.js:40:36) at ChildProcess.emit (events.js:198:13) at ChildProcess.EventEmitter.emit (domain.js:466:23) at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12) [14:24:26] 'webpack:dev' errored after 1.23 min [14:24:26] 'watch-proxy' errored after 1.23 min [14:24:26] The following tasks did not complete: , browser-sync-proxy, [14:24:26] Did you forget to signal async completion? npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! adonis-fullstack-app@4.1.0 proxy: gulp watch-proxy npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the adonis-fullstack-app@4.1.0 proxy script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:

LukeMc92 commented 4 years ago

The Adonis serve --dev runs perfectly fine but when i run npm run proxy it starts up and then after a few minutes its sends the message above.

LukeMc92 commented 4 years ago

@AquilaSagitta's solution worked for me. It seems like this issue arises anytime you have a task or subtask that runs multiple functions, because JavaScript is asynchronous. So any task that calls more than one function needs to call done, which will wait for all the tasks to finish & then exit that block of the promise.

Under the hood I suspect that calling gulp returns a promise, and each task requires a promise resolve or reject because recent versions of node require explicit promise resolutions, probably to do with supporting async/await syntax. In a task that only calls one function, returning the function seems to suffice.

So in @AquilaSagitta's example, it's probably either styles or scripts in gulp.parallel that needs to call done. I THINK that every gulp method automatically returns the gulp promise on complete, but gulp.parallel might not? -- so it could be gulp.parallel throwing the promise error.

Here's where the error arose for me:

gulp.task( 'watch-proxy', gulp.parallel([ gulp.series([ 'webpack:dev', 'styles', function runningWatch() { gulp.watch('./resources/scss//*', gulp.parallel('styles')); gulp.watch('./resources/js/*/', gulp.parallel('webpack:dev')); gulp.watch(['./public//', './public/']).on('change', reload); }, ]), gulp.series(['browser-sync-proxy']), ]),

Webpack:dev threw the error, and watch-proxy also threw the error, because its return value depends on the return values of its children. webpack:dev looked like this:

gulp.task( 'webpack:dev', ( gulp.series(cb => { return exec('npm run dev:webpack', function(err, stdout, stderr) { console.log(stdout); console.log(stderr); cb(err); }); }) );

And the fix was to add the done parameter to a function in webpack:dev & call it at the end.

gulp.task( 'webpack:dev', (done) =>{ gulp.series(cb => { return exec('npm run dev:webpack', function(err, stdout, stderr) { console.log(stdout); console.log(stderr); cb(err); }); }) done(); });