Skip to content

reflex export fails with rx.code_block due to ESM/CJS interop in react-syntax-highlighter #6054

Closed

Description

@daeunnniii

Describe the bug
After upgrading to Reflex 0.8.23, using rx.code_block causes reflex export to fail due to an ESM/CJS interop error originating from react-syntax-highlighter.
This issue does not occur in development mode and only reproduces during the export (production build) step.

Error [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/refractor/lib/core.js
from .../node_modules/react-syntax-highlighter/dist/cjs/prism-light.js not supported.
    at Object.<anonymous> (.../node_modules/react-syntax-highlighter/dist/cjs/prism-light.js:9:13)
    ...
error: script "export" exited with code 1

To Reproduce
Steps to reproduce the behavior:

  • Code/Link to Repo:
import reflex as rx

def index():
    return rx.code_block(
        "print('hello world')",
        language="python",
    )

app = rx.App()
app.add_page(index)
~$ reflex export

Expected behavior
reflex export should complete successfully when rx.code_block is used, producing a valid production build.

Screenshots
If applicable, add screenshots to help explain your problem.
Image

Specifics (please complete the following information):

  • Python Version: 3.12
  • Reflex Version: 0.8.23
  • Node Version: 22.11.0 (reproduces on Node.js 21 and above)
  • OS: Ubuntu 22.04

Activity

  1. added a commit that references this issue on Dec 17, 2025
    0708694
  2. adhami3310 commented on Dec 19, 2025

    @adhami3310
    Member

    i cannot reproduce this :/ not sure what i specifically have that's different

  3. daeunnniii commented on Dec 22, 2025

    @daeunnniii
    Author

    Thanks for checking.

    It seems to be patch-version dependent, which likely explains why it doesn’t reproduce consistently.

    On my side:

    • It works on Node 24.12.0 and Node 22.21.1
    • It fails on Node 22.11.0 and Node 21.7.3
    • The failure only occurs during reflex export, not in development mode

    From the logs, the difference comes from SSR externalization during the export build. In the failing cases, react-syntax-highlighter is externalized and ends up being resolved by the Node SSR runtime, which then hits a CJS → ESM interop issue (refractor).

    The purpose of this PR is to avoid delegating this resolution to the Node SSR runtime during export builds and let the bundler handle the ESM/CJS interop consistently. That’s why the proposed change limits ssr.noExternal to the build step only.

    I’m happy to share debug logs or more environment details if that would be helpful.

  4. masenf commented on May 22, 2026

    @masenf
    Collaborator

    Minimum node version supported by reflex is bumped to 22.12.0 to avoid this issue entirely.

    Confirmed bug is not present in 22.12.0 23.0.0 and 24.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions