From d4e02f45473ac383be5be57f0f3e603312f4ccff Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Sun, 27 Oct 2024 12:00:34 +0100 Subject: [PATCH] Ensure ESM compilation correctly detects file extension (#7446) * Ensure ESM compilation correctly detects file extension * Treat .js files as .jsx when using ReactComponent --- panel/io/compile.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/panel/io/compile.py b/panel/io/compile.py index 0df128571a..d69211d306 100644 --- a/panel/io/compile.py +++ b/panel/io/compile.py @@ -297,7 +297,7 @@ def generate_project( name = component.__name__ esm_path = component._esm_path(compiled=False) if esm_path: - ext = esm_path.suffix + ext = esm_path.suffix.lstrip('.') else: ext = 'jsx' if issubclass(component, ReactComponent) else 'js' code, component_deps = extract_dependencies(component) @@ -391,6 +391,8 @@ def compile_components( print(f"An error occurred while running npm install:\n{RED}{e.stderr}{RESET}") # noqa return None + if any(issubclass(c, ReactComponent) for c in components): + extra_args.append('--loader:.js=jsx') if minify: extra_args.append('--minify') if out: