Comments (8)
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.
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.
Can a bundle be used regardless if an error occurred? I think you should not catch them.
from webpack.
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.
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.
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.
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.
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.
from webpack.
Related Issues (20)
- Webpack build error for second time HOT 1
- `exportsPresence` does not work for unused imports HOT 3
- Implement ability to use "node:" prefixes for Node.js core modules HOT 1
- mangled exports breaks with destructuring assignment of JSON imports HOT 7
- there are confusing JDocs code
- Potential bug issues
- Webpack is not resolving node_modules specified in `resolve.modules` property.
- Dynamically loading chunks
- [Code implementation issues] ArrayQueue
- [feature] create cli HOT 3
- Not able to build node script
- bootstrap:27 Uncaught TypeError: __webpack_require__.nmd is not a function
- Self-reference dependency has unused export name when imported inside of a web worker
- support `import.meta.dirname` and `import.meta.filename` HOT 2
- <!-- identifier: admin-actions -->
- Remote into Web Component from React giving an error saying " Module does not exist in container"
- Multiple DefinePlugin instances cause aggressive cache invalidation due to collisions HOT 7
- Webpack fails when importing module
- import .scss build to js, the exported mapping is inconsistent with the usage【Urgent!!】
- Unused code elimination and deduplication is not applied when using sass's api: 'legacy' setting
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webpack.