Skip to content

Document webpack change: Add loader name to error message. Resolves #2878 #2231

@webpack-bot

Description

@webpack-bot

A pull request by @mc-zone was merged and maintainers requested a documentation change.

See pull request: webpack/webpack#6542


What kind of change does this PR introduce?
Feature.

Did you add tests for your changes?
Yes.

If relevant, link to documentation update:
N/A

Summary
Add loader name to Error message so that people can actually realize which loaders were emiting these errors clearly.

Demo:

webpack.config.js:

module.exports = {
  entry:"./index.js",
  output:{
    path:path.resolve(__dirname, "./dist"),
    filename:"[name].bundle.js",
  },
  mode:"development",
  module: {
    rules: [
      {
        test: /\.test$/,
        use: [
          "babel-loader",
          {
            loader:path.resolve(__dirname, './test-loader.js'),
          }
        ]
      },
    ]
  },
};

test-loader.js:

module.exports = function(source){
  this.emitWarning(new Error("This is a emit Warning"));
  this.emitError(new Error("This is a emit Error"));
  return source;
};

lib.test:

);a
console.log("I'm test");

Current output:

image

After this PR:

image

Resolves #2878.

Does this PR introduce a breaking change?
Nope (I think).

Other information
Note: This feature also need some changes in webpack/loader-runner to handle errors from throw and callback(error) (need add loader name to error.from). I will add it subsequently.
Updated: Now using loaderContext.loaderIndex in NormalModule.js for all to determine which loader the error is belong to .

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