diff --git a/src/index.js b/src/index.js index 5fbdd933..826bdbf9 100644 --- a/src/index.js +++ b/src/index.js @@ -14,12 +14,13 @@ const fs = require("fs"); */ function BabelLoaderError(name, message, codeFrame, hideStack, error) { Error.call(this); - Error.captureStackTrace(this, BabelLoaderError); this.name = "BabelLoaderError"; this.message = formatMessage(name, message, codeFrame); this.hideStack = hideStack; this.error = error; + + Error.captureStackTrace(this, BabelLoaderError); } BabelLoaderError.prototype = Object.create(Error.prototype); diff --git a/test/loader.test.js b/test/loader.test.js index f9f0883d..11cf7762 100644 --- a/test/loader.test.js +++ b/test/loader.test.js @@ -263,3 +263,21 @@ test.cb("should not throw without config", t => { t.end(); }); }); + +test.cb( + "should return compilation errors with the message included in the stack trace", + t => { + const config = Object.assign({}, globalConfig, { + entry: path.join(__dirname, "fixtures/syntax.js"), + output: { + path: t.context.directory, + }, + }); + webpack(config, (err, stats) => { + const moduleBuildError = stats.compilation.errors[0]; + const babelLoaderError = moduleBuildError.error; + t.regex(babelLoaderError.stack, /Unexpected character/); + t.end(); + }); + }, +);