-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Esbuild causing unhandledRejection #3219
Comments
I was unable to reproduce this. Here's what I tried: const esbuild = require('esbuild')
async function run() {
try {
await esbuild.build({
entryPoints: ['entry'],
plugins: [{
name: 'temp',
setup(build) {
build.onResolve({ filter: /./ }, () => new Promise(() => { }))
},
}],
})
}
// Comment this out to cause an unhandled rejection
catch (err) { console.log('Caught:', err) }
finally { }
}
process.on('unhandledRejection', err => {
console.log('UNHANDLED REJECTION')
throw err
})
console.log('Waiting for Ctrl+C...')
process.on('SIGINT', () => {
console.log('Waiting for timeout...')
setTimeout(() => console.log('Success'), 2000)
})
run() It seems like esbuild is successfully funnelling the error to the Please provide a way to reproduce the issue. I'm marking this as
Agreed, and I'd like to fix this. It should be straightforward to fix this if I can reproduce it. |
Below is a script that allows me to reproduce the
Here is the script: const esbuild = require('esbuild');
async function main() {
console.log('building...');
await esbuild.build({
entryPoints: ['entry.js'],
write: false,
bundle: true,
plugins: [{
name: 'loader',
setup: (build) => {
build.onResolve({ filter: /()/ }, async (args) => {
return { path: args.path, namespace: 'fake' };
});
build.onLoad({ filter: /()/, namespace: 'fake' }, async (args) => {
await sleep(2000);
if (args.path === 'entry.js') {
return {
loader: 'js',
contents: 'console.log(require("string.js"));',
};
}
if (args.path === 'string.js') {
return {
loader: 'js',
contents: 'module.exports = "hello world";',
};
}
});
},
}],
});
console.log('done!');
}
async function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
process.on('SIGHUP', () => console.log('SIGHUP detected'));
process.on('SIGINT', () => console.log('SIGINT detected'));
process.on('SIGTERM', () => console.log('SIGTERM detected'));
process.on('unhandledRejection', (err) => {
console.log('Unhandled rejection:', err);
});
main().catch((err) => {
console.log('Error caught:', err);
}); The output I get is:
|
Thanks for fixing this! 👍 |
I have a program that uses esbuild internally. My program is designed such that it can be cancelled at any time via
ctrl+c
(SIGINT). When a SIGINT is received, it doesn't just exit the process abruptly, rather, it initiates a graceful shutdown procedure. However, sometimes when I do this, I get anunhandledRejection
event from esbuild. It doesn't happen all the time; it's inconsistent, probably due to the timing of things.Anyways, esbuild should never cause
unhandledRejection
events. I'm doingawait esbuild.build()
and catching any thrown errors within atry-catch
block, so it should (ideally) be impossible for any errors within esbuild to escape asunhandledRejection
events.Here is the complete stderr output:
The version of esbuild is
0.18.10
.The text was updated successfully, but these errors were encountered: