Skip to content

Expose onError hook or allow Error config option #577

Closed

Description

@nkoterba

Hello -

I'm trying to use rollup in a gulp pipeline:

gulp.task('build', () => {
    return gulp.src(mainJsFile)
        .on('error', handleErrors)
        .pipe(rollup({
            sourceMap : true,
            format    : 'iife',
            moduleName: 'defense'
        }))
        .pipe(babel())
        .pipe(rename(outputBundleName))
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest(outputDir))
        .pipe(gulp.dest('../dist/defense'));
})

I then am using gulp-watch (not the build-in gulp.watch), to provide live-reload of assets, etc. However, if there's a syntax error in one of the files rollup is trying to process, I get the following stack trace:

events.js:141
      throw er; // Unhandled 'error' event
      ^
SyntaxError: Unexpected token (28:0) in code/src/directives/editable-list/editable-list.directive.es6.js
    at Parser.pp$4.raise (code/node_modules/rollup/dist/rollup.js:4288:13)
    at Parser.pp.unexpected (code/node_modules/rollup/dist/rollup.js:2744:8)
    at Parser.pp$3.parseExprAtom (code/node_modules/rollup/dist/rollup.js:3891:12)
    at Parser.pp$3.parseExprSubscripts (code/node_modules/rollup/dist/rollup.js:3780:19)
    at Parser.pp$3.parseMaybeUnary (code/node_modules/rollup/dist/rollup.js:3761:19)
    at Parser.pp$3.parseExprOps (code/node_modules/rollup/dist/rollup.js:3715:19)
    at Parser.pp$3.parseMaybeConditional (code/node_modules/rollup/dist/rollup.js:3697:19)
    at Parser.pp$3.parseMaybeAssign (code/node_modules/rollup/dist/rollup.js:3674:19)
    at Parser.pp$3.parseExprList (code/node_modules/rollup/dist/rollup.js:4215:157)
    at Parser.pp$3.parseExprAtom (code/node_modules/rollup/dist/rollup.js:3870:28)

Ideally, I would be able to handle the error from rollup, and not exit my gulp watch process so that I can fix the syntax error and continue with hot/live reload.

Is this a planned future extension? Am I missing something obvious now how to do this?

Activity

  1. TrySound commented on Mar 28, 2016

    @TrySound
    Member

    @nkoterba You should use rollup-plugin-babel to process a lot of cases which rollup does not support (es7 or jsx for example). Also you don't need to use any gulp wrappers. Use rollup directly like here https://github.com/TrySound/case/blob/master/gulpfile.js#L22-L46

  2. TrySound commented on Mar 28, 2016

    @TrySound
    Member

    @nkoterba About gulp3.*. You should catch every "error ready" pipe. And you need just pass native callback to error listener. The last pipe will be always catched. The problem is that errors do not bubble in the pipe. It was fixed in gulp4 which is not released yet, but I still use it.

    gulp.task('style', function (done) {
      return gulp.src('src/main.css')
        .pipe(postcss([some plugins]))
        .on('error', done)
        .pipe(gulp.dest('dist'));
    });
  3. nkoterba commented on Mar 28, 2016

    @nkoterba
    Author

    @TrySound Thanks for the info. I re-did our build system to use straight rollup, babel, etc. as you suggested. Thanks for the clear/clean code example. We were piping our original gulp output to two destinations but a second gulp task allows us the same functionality.

    As for the errors, when I moved to the straight rollup implementation it appears that errors no longer trip up the 'gulp stream' (since there isn't one anymore) so hot/live reload works as expected:

    • Compile errors are displayed in console but no re-bundling occurs
    • When the errors are fixed, re-bundling automatically occurs and the UI is updated.

    Thanks again for the quick response and support!

    (p.s. we are using es6 with gulp which relies on 'es2015' preset in the .babelrc file. To workaround it, I updated our rollup options to be:

                babel({
                    exclude  : 'node_modules/**',
                    babelrc  : false,
                    presets : 'es2015-rollup'
                }),

    )

  4. tunnckoCore commented on Sep 13, 2017

    @tunnckoCore

    I'm strongly for onerror hook too. I think to use eslint plugin which i will configure to throw on style errors/warnings, so i want to see more clearly the output of the ESLint, not that the plugin is failed.

    error: 'foo' is assigned a value but never used (no-unused-vars) at src/index.js:3:7:
      1 | import add from './add.js'
      2 |
    > 3 | const foo = 123
        |       ^
      4 | console.log(add({ a: 1, b: 2, c: 123 }))
      5 |
    
    
    1 error found.
    [!] (eslint plugin) Error: Errors were found
    src/index.js
    Error: Errors were found
        at error (/home/charlike/github/wooh/node_modules/rollup/dist/rollup.js:185:14)
        at Object.error (/home/charlike/github/wooh/node_modules/rollup/dist/rollup.js:9141:6)
        at promise.then.previous (/home/charlike/github/wooh/node_modules/rollup/dist/rollup.js:9150:32)
        at <anonymous>
        at process._tickCallback (internal/process/next_tick.js:188:7)
        at Function.Module.runMain (module.js:611:11)
        at startup (bootstrap_node.js:158:16)
        at bootstrap_node.js:598:3
    
    error Command failed with exit code 1.
    ERROR: "build:node" exited with 1
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions