Skip to content
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

Plugins ignored after 2nd item in list #2607

Open
caseybaggz opened this issue Oct 12, 2022 · 4 comments
Open

Plugins ignored after 2nd item in list #2607

caseybaggz opened this issue Oct 12, 2022 · 4 comments
Labels

Comments

@caseybaggz
Copy link

I'm using the latest version of esbuild

Current Behavior

When running the esbuild.build script, I'm running into a weird issue where the method will ignore plugins after the second one in the list. If I swap the plugins in position 2/3 the latter one works and previous one doesn't.

Expected Behavior

The plugins in the list should run in order from first to last without being ignored.

Steps to reprodce

  1. Go here: https://github.com/pluralsight/tva/pull/676/files#diff-43d4aa6292fbf97935d4a2f7aa03a8935956f66f1a52ff0b4421e5ad5b73c9cf
  2. Clone branch and run yarn create:bundles
  3. Should see BABEL WORKING... logged
  4. ERROR - will not see REPLACE WORKING... logged - but it should
@hyrious
Copy link

hyrious commented Oct 12, 2022

This is because onLoad is being called only once per file. Your babel plugin and replace plugin both want to load a file, but only one of them could take control. See #1902 and https://gist.github.com/hyrious/ac6fd074c2f6d24a306c3a0970617cbc

I'd recommend you to write an all-in-one plugin that do all works in one onLoad currently.

@caseybaggz
Copy link
Author

caseybaggz commented Oct 13, 2022

@hyrious but that seems like a flaw in the esbuild system though since it is how all other bundlers work? Making an all in one will solve the problem, but it's a band-aid because we should be able to stack multiple esbuild plugins in a list vs one giant plugin (which contradicts clean coding practices).

In theory, the patch you are recommending is this:

plugins: [thirdParty, allIinOnePrivate, thirdParty]

Which will still fail.

I feel like esbuild should definitely be able to handle this case and allow the standard plugin syntax:

plugins: [thirdParty, private, thirdParty, thirdParty, etc.]

@caseybaggz
Copy link
Author

Ah, OK, I see this small line here in the plugin docs that only one plugin in the list should return the contents which tells esbuild to stop and move on to the next step, which aligns with what you were saying.

"For a given module, all onLoad callbacks from all plugins will be run in the order they were registered until one takes responsibility for loading the module. If no callback returns contents for the module, esbuild will run its default module loading logic."

Guessing all esbuild plugins should essentially not return contents to ensure the entire list gets looped through? 🤷‍♀️

@evanw evanw added the plugins label Apr 4, 2023
@segevfiner
Copy link

It would be helpful to be able to invoke more than one onLoad callback or some different callback though for plugins that transform the code but otherwise want other plugins to work. This is quite an annoying limitation of esbuild currently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants