Problem/Motivation

When saving JavaScript which may contain syntax errors Babel will return an error. Currently this error is just thrown causing the process to crash and no additional changes are watched/saved.

[07:27:09] Watching './**/*.es6.js' for changes.
[07:27:19] 'misc/ajax.es6.js' is being processed.
~/drupal/core/scripts/js/compile.js:21
        throw new Error(err);
        ^

Error: SyntaxError: misc/ajax.es6.js: Unexpected token (13:10)
    at babel.transformFile (~/drupal/core/scripts/js/compile.js:21:15)
    at ~/drupal/core/node_modules/babel-core/lib/api/node.js:141:7
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:438:3)
error Command failed with exit code 1.

Proposed resolution

Catch and log the error, don't crash the watch process.

$ node ./scripts/js/babel-es6-watch.js
[07:26:13] Watching './**/*.es6.js' for changes.
[07:26:36] 'misc/ajax.es6.js' is being processed.
[07:26:37] SyntaxError: misc/ajax.es6.js: Unexpected token (13:10)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

droplet created an issue. See original summary.

Wim Leers’s picture

Can you describe what the behavior before vs after is, in other words: what this fixes or improves?

GrandmaGlassesRopeMan’s picture

Title: Install a bumper on JS watch:js script » Log JavaScript transpile errors instead of crashing the watcher process.
Issue summary: View changes
Issue tags: -Needs issue summary update +JavaScript
Wim Leers’s picture

Priority: Normal » Major
Issue tags: +DX (Developer Experience)

Ahhh! Yes! I've had this happen too! And because of this, I've posted patches where the ES5 transpiled file was out of sync with the ES6 file. Which can lead to all sorts of confusion.

Therefore bumping priority and tagging DX.

GrandmaGlassesRopeMan’s picture

Status: Needs review » Reviewed & tested by the community

  • cilefen committed e715e5f on 8.5.x
    Issue #2885595 by droplet: Log JavaScript transpile errors instead of...

  • cilefen committed 1ead5f1 on 8.4.x
    Issue #2885595 by droplet: Log JavaScript transpile errors instead of...
cilefen’s picture

Status: Reviewed & tested by the community » Fixed

If it makes everybody's life easier, let's do it.

cilefen’s picture

...and I made sure this preserves the non-zero exit code as needed for pre-commit scripts, which is appreciated (and needed).

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.