aspect-build / rules_esbuild

Bazel rules for https://esbuild.github.io/ JS bundler
https://docs.aspect.build/rules/aspect_rules_esbuild
Apache License 2.0
27 stars 27 forks source link

fix: allow root repositories to override esbuild toolchain version under bzlmod #164

Closed satajo closed 11 months ago

satajo commented 12 months ago

Fixes the problem where overriding the default esbuild version in MODULE.bazel results in the error Multiple conflicting toolchains declared for name esbuild.

The solution is an adapted copy of @kormide's fix to a similar problem under rules_nodejs.

satajo commented 12 months ago

For context, I ran into this issue by wanting to use css-modules with esbuild. After some confusion about why the class name substitutions did not work in the bundled output, it turned out that esbuild was defaulting to version 0.16.7 which does not support css-modules.

Attempting a simple version override with the following configuration resulted in the error about conflicting toolchain names.

bazel_dep(
    name = "aspect_rules_esbuild",
    version = "0.15.3",
)

esbuild = use_extension("@aspect_rules_esbuild//esbuild:extensions.bzl", "esbuild")

esbuild.toolchain(name = "esbuild", esbuild_version = "0.19.2")

Defining a toolchain with some other name than "esbuild" did work, but I was not able to figure out how to actually use the alternative toolchain with the esbuild rule. I did not check whether override using WORKSPACE syntax would have worked because I am trying to stick with MODULE.bazel usage if possible.

After finding out about the similar issue regarding rules_nodejs, the fix seemed simple enough and now the override definition above works, as do my css-modules.