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 overwrites custom objects passed into resolve.unsafeCache HOT 11
- Error: Uncaught ReferenceError: __webpack_require__ is not defined at HOT 2
- Option to keep /*webpackIgnore:true*/ in the bundle
- Can't import child_process HOT 1
- Module Federation loadRemoteModule catch error E[n].get is not a function
- Resolver type from webpack/enhanced-resolve are not compatible HOT 3
- v5.90.3 pollution global variables jquery $
- License scan badge shown as failing HOT 10
- `snapshot.unmanagedPaths` is ignored
- Module Federation - Some chunks are not loaded when navigating from the Remote module to the Host module
- failed to import ffmpeg-core.js HOT 1
- Webpack 5 doesnt generate the chunks of imports HOT 1
- Error: Cannot find module 'webpack-cli/package.json' HOT 2
- Unable to bust cache of module federation remotes....
- Re-exported Ant Design components don't have same style with the original components
- failed to import ffmpeg-core.js HOT 3
- DllPlugin: When processing multiple chunks, does the `path` option must have a string template?
- Webpack BannerPlugin with `raw` option should put `use strict` on the very first line HOT 10
- After webpack 5 migration not able to use local packages in a mono repo
- 95% emitting emit phase takes much longer in Node >=16
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.