question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Errors contain ANSI Escape Codes

See original GitHub issue

If I run babel directly in bash on a file with a syntax error, it outputs a nice colored error message that points to the syntax error.

When I do the same thing via gulp/browserify/babelify, the output contains raw ANSI escape codes. It’s as if whatever is retrieving the output of babel is escaping it, causing the embedded escape codes to be, well, escaped. This makes the error message really difficult to understand, slowing down development.

My gulp task looks like this:

var b = browserify({
    entries: PATHS.mainjs,
    debug: true,
    noParse: ["jquery"]
});
b.on('log', gutil.log);

b = b.transform(babelify);

return b.bundle()
    .pipe(source(PATHS.bundlejs))
    .on('error', gutil.log)
    .pipe(gulp.dest(PATHS.dist + '/js'));

The error looks like this:

SyntaxError: d:/git/exceptionsweb/src/js/pages/app.js: Unexpected token (43:14)
?[0m  41 |                                              ?[36mthis?[39m?[1m.?[22mstate?[1m.?[22mprojectsLoading
  42 |                                                  ?[1m??[22m ?[1m<?[22mdiv?[1m>?[22mLoading?[1m...?[22m?[1m<?[22m?[1m/?[22mdiv?[1m>?[22m

The “?” are actually the escape character, but that doesn’t translate well here.

I’m also not really sure how this error is being output. It’s not coming from my on(“error”) callback, because I get it even if I comment that out. Same with on(“log”). It’s like babel is writing directly to the output.

babelify 6.3.0 babel-core 5.8.25 gulp 3.9.0

Any help would be appreciated!

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
InfinitiesLoopcommented, Oct 7, 2015

Here we go, getting fancy now.

    .on("error", function(err) {
        if (err && err.codeFrame) {
            gutil.log(
                gutil.colors.red("Browserify error: "),
                gutil.colors.cyan(err.filename) + ` [${err.loc.line},${err.loc.column}]`,
                "\r\n" + err.message + "\r\n" + err.codeFrame);
        }
        else {
            gutil.log(err);
        }
        this.emit("end");
    })
1reaction
InfinitiesLoopcommented, Oct 7, 2015

Thanks. I settled on this after some searching:

    .on("error", function(err) {
        gutil.log(err.message + "\r\n" + err.codeFrame);
        this.emit("end");
    })

That seems to give a nice output, but I’m unsure whether all the types of errors it might get would map well to this. Thanks for your help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

ANSI escape code - Wikipedia
ANSI escape sequences are a standard for in-band signaling to control cursor location, color, font styling, and other options on video text terminals...
Read more >
Everything you never wanted to know about ANSI escape codes
Everything you never wanted to know about ANSI escape codes. 2019-02-13. See also: Flash cards (Anki deck) for memorization.
Read more >
Don't Trust This Title: Abusing Terminal Emulators with ANSI ...
We saw how ANSI escape characters from DevOps systems like OpenShift or Kubernetes have a connection through terminals and how it can affect...
Read more >
Why do ANSI escape codes sometimes work in CMD
What you're searching for is ENABLE_VIRTUAL_TERMINAL_PROCESSING . The reason it sometimes "stops working", is because some applications ...
Read more >
Unable to use ANSI Escape Sequences in Windows 10
Those aren't complete escape sequences; they're missing the actual ESC character (byte 0x1B) in front of the [7m . In other languages you ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found