esbuild icon indicating copy to clipboard operation
esbuild copied to clipboard

Throwing an error within a plugin does not stop the build

Open JoaquinFernandez opened this issue 1 year ago • 1 comments

Details

When creating a plugin, throwing an error inside it won't stop the build, it will just cause it to timeout.

How to reproduce

I didn't know how to create a repro on the playground for a plugin, so I am pasting the code of the plugin here:

import { Plugin, PluginBuild } from 'esbuild';

export const moduleExportsPlugin = (): Plugin => ({
  name: 'module-exports',
  setup(build: PluginBuild) {
    build.onEnd(_result => {
      throw new Error('module.exports already exists, unknown use case');
    });
  },
});

Versions

It seems a regression, in v0.16.x It worked fine, since 0.17.x it causes the unexpected behaviour

JoaquinFernandez avatar May 06 '24 22:05 JoaquinFernandez

I can't reproduce this. Here's what I tried:

require('esbuild').build({
  plugins: [{
    name: 'name',
    setup(build) {
      build.onEnd(() => {
        throw new Error
      })
    },
  }],
}).then(
  () => console.log('success'),
  () => console.log('failure'),
)

That prints failure on the latest version of esbuild. You can also see this live in the playground.

evanw avatar Jun 15 '24 15:06 evanw