diff --git a/.changeset/fix-browserslist-pnpm.md b/.changeset/fix-browserslist-pnpm.md new file mode 100644 index 0000000000..2d4febea0d --- /dev/null +++ b/.changeset/fix-browserslist-pnpm.md @@ -0,0 +1,12 @@ +--- +"@asyncapi/generator": patch +--- + +Fix browserslist error when using pnpm + +Set BROWSERSLIST_ROOT_PATH environment variable during template compilation +to prevent browserslist from searching outside the template directory. This +fixes an issue where pnpm's shim files were incorrectly parsed as browserslist +configuration, causing "Unknown browser query" errors. + +Fixes: https://github.com/asyncapi/cli/issues/1781 \ No newline at end of file diff --git a/apps/generator/lib/generator.js b/apps/generator/lib/generator.js index 5a3f796022..86bf7ca775 100644 --- a/apps/generator/lib/generator.js +++ b/apps/generator/lib/generator.js @@ -401,7 +401,22 @@ class Generator { */ async configureTemplate() { if (this.compile) { - await configureReact(this.templateDir, this.templateContentDir, TRANSPILED_TEMPLATE_LOCATION); + // Set BROWSERSLIST_ROOT_PATH to prevent browserslist from searching + // outside the template directory. This fixes issues with pnpm where + // browserslist would incorrectly parse pnpm shim files as config. + // See: https://github.com/asyncapi/cli/issues/1781 + const previousRootPath = process.env.BROWSERSLIST_ROOT_PATH; + process.env.BROWSERSLIST_ROOT_PATH = this.templateDir; + try { + await configureReact(this.templateDir, this.templateContentDir, TRANSPILED_TEMPLATE_LOCATION); + } finally { + // Restore previous value if it existed + if (previousRootPath === undefined) { + delete process.env.BROWSERSLIST_ROOT_PATH; + } else { + process.env.BROWSERSLIST_ROOT_PATH = previousRootPath; + } + } } }