Skip to content
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

Breaks when logError tries to emit the end event #680

Closed
DKvistgaard opened this issue Apr 6, 2018 · 4 comments
Closed

Breaks when logError tries to emit the end event #680

DKvistgaard opened this issue Apr 6, 2018 · 4 comments

Comments

@DKvistgaard
Copy link
Contributor

DKvistgaard commented Apr 6, 2018

The logError function breaks the Gulp task as it tries to emit an end event.

After changing the logError function to an arrow function it has lost it's correct reference to the this operator, which causes it to break.
Instead of being a reference to the stream the this operator in this setup is a reference to gulpSass.

Versions

  • gulp 3.9.1
  • gulp-sass 4.0.0
  • npm 5.8.0
  • node 8.9.1

Gulp Task

gulp.task('styles', () => {
    return gulp.src('app/styles/style.scss')
        .pipe($.sass().on('error', $.sass.logError))
        .pipe(gulp.dest('dist/styles'));
});

Error Message

/node_modules/gulp-sass/index.js:156
  this.emit('end');
       ^

TypeError: this.emit is not a function
    at DestroyableTransform.gulpSass.logError (/node_modules/gulp-sass/index.js:156:8)
    at emitOne (events.js:121:20)
    at DestroyableTransform.emit (events.js:211:7)
    at onwriteError (/node_modules/readable-stream/lib/_stream_writable.js:354:10)
    at onwrite (/node_modules/readable-stream/lib/_stream_writable.js:371:11)
    at WritableState.onwrite (/node_modules/readable-stream/lib/_stream_writable.js:126:5)
    at afterTransform (/node_modules/readable-stream/lib/_stream_transform.js:81:3)
    at TransformState.afterTransform (/node_modules/readable-stream/lib/_stream_transform.js:58:12)
    at errorM (/node_modules/gulp-sass/index.js:118:12)
    at Object.callback (/node_modules/gulp-sass/index.js:127:16)

Idea for solution
Change the logError function declaration from:

gulpSass.logError = (error) => {
    ...
};

To:

gulpSass.logError = function logError(error) {
    ...
};

That way the logError gets its own this operator, which in this case is the desired stream and thereby the this.emit('end'); function will work again.

I'll happily create a PR for this fix if you wish.

@xzyfer
Copy link
Collaborator

xzyfer commented Apr 6, 2018 via email

@xzyfer
Copy link
Collaborator

xzyfer commented Apr 6, 2018 via email

@DKvistgaard
Copy link
Contributor Author

DKvistgaard commented Apr 6, 2018

@xzyfer Oh yeah $ is a reference to all gulp plugins loaded in with gulp-load-plugins. Just so we don't have to write a require statement for each gulp plugin in our gulpfile. :)

Ok great. Let me know if you need me to create a PR or need any further info.

@xzyfer
Copy link
Collaborator

xzyfer commented Apr 6, 2018 via email

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