Git Product home page Git Product logo

Comments (8)

sokra avatar sokra commented on March 29, 2024

It is reported in the errors member of the resulting stats or in red on command line.
You can throw an exception if you want to.

if(stats.errors.length > 0) {
  throw new Error(stats.errors.join("\n"));
}

You even get multiple errors reported each with a stack trace... :)

from webpack.

jhnns avatar jhnns commented on March 29, 2024

I've thought about this quite a while. I understand your concerns why you think it's better to collect errors.

But as the bundling is a critical process you can't just proceed if an error occurs. While I was developing it never occurred to me that there was an ignorable error. If an error isn't ignorable it should be thrown so the developer knows that something went wrong. This only leads to situations where webpack-unexperienced developers ask themselves wtf is going on because they can't see any error.

from webpack.

jhnns avatar jhnns commented on March 29, 2024

Can a bundle be used regardless if an error occurred? I think you should not catch them.

from webpack.

sokra avatar sokra commented on March 29, 2024

Yes.

i. e. in this case

var module;
try {
  module = require("missing-module");
} catch(e) {
  module = require("replacement-module");
}

This would case an error while compiling, but the bundle can be used.

from webpack.

jhnns avatar jhnns commented on March 29, 2024

If this code is within a module that I want to bundle, this would not cause an error because it is caught :). I don't know a situation where I might require a possible missing module without wrapping it within try-catch or using require.resolve before.

from webpack.

sokra avatar sokra commented on March 29, 2024

That is client side code, which cannot catch loader errors, which are thrown at compile time.

If I would throw an error if the missing-module is missing (or loader failed) that error would cause in "no bundle generated, because of error" and the client side code would never be executed, even if it could handle the missing module.

Therefore I decided to accept little errors (like missing modules, loader errors) and generate the bundle. On runtime there is an error thrown that a module is missing (like node.js would throw it). You can choose to accept some errors.

If you don't want to accept errors if(stats.errors[0]) throw stats.errors[0]; ;)

A nice reporting would be better. i.e. the (new) webpack-dev-server display the errors in the browser.

from webpack.

jhnns avatar jhnns commented on March 29, 2024

Ok, now I get it. I was wrong, sorry.

However, I think webpack should not collect errors by default. I think it's much more usual to stop on every error. You may introduce an option like collectErrors. I've been experimenting with client-side bundlers for more than a year and I've never seen an error that can be ignored.

from webpack.

sokra avatar sokra commented on March 29, 2024

Maybe I'll change it for 0.7

I'll check than if a require call is in a try block and thead this cases only as warnings. Than all errors are critical and can be thrown. For watch mode there will be a new error type StoppingError which will be thrown if a error causes webpack's watch mode to stop.

Ideas

from webpack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.