New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using this.error
outside the transformation context
#4424
Comments
No. What But you can use |
Out of curiosity: Is it possible to use |
I guess there should be a distinction between failing the build and exiting the whole process with code 1. Is there a way to mimic this behavior inside other hooks such as |
It should not abort watchMode if you throw in |
Ok, in my experiments, throwing in |
Created #4427 as a fix, please give it a go |
So regarding this, I did my investigation and you are right, the problem was that I was using
But as you stated, I still have a problem with the |
I was wondering why you did not simply run Otherwise, it kind of works for me (in the least, the watch process was never aborted), except for two things: function onBuildStartPlugin() {
return {
name: 'onWatchThrow',
async buildStart() {
this.addWatchFile(filePath);
emitError();
},
async watchChange() {
emitError();
},
};
}
function emitError() {
const file = readFileSync(filePath, 'utf8');
if (file.includes("console.log('error')")) {
this.error(new Error('Stop the process'));
}
}
|
The preferred way is use the rollup api of course but I don't see how it's possible. |
I will see how much work it would be to allow the |
I pushed a potential solution to #4427 which will make the |
Amazing, I tried this branch and it works as expected! |
We want to run some processes in
buildStart
andwatchChange
in a plugin that I work on. The process needs to emit diagnostics and wish to use the rollup API to show the user those diagnostics, but it always throws when we usethis.error
outside thetransform
hook.Is there a way to use this API and recover from the error in other hooks?
The text was updated successfully, but these errors were encountered: