Skip to content

Switching to plugin-react-oxc triggers "$RefreshReg$ is not defined" errors #514

@blixt

Description

@blixt

Related plugins

Describe the bug

Switching from the normal @vitejs/plugin-react in vite.config.ts to the @vitejs/plugin-react-oxc plugin and not changing anything else makes the code in dev/watch mode crash with Uncaught ReferenceError: $RefreshReg$ is not defined if you're using modules from a different context than the main frame (e.g. a Worker). If I look at the code that triggered it, it's usually something like this:

export const MODULE_TYPE_TO_DOMAIN = {
    something: "SomethingElse",
    // ...
};
export const MODULE_DOMAIN_TO_TYPE = swapKeysAndValues(MODULE_TYPE_TO_DOMAIN);
_c = MODULE_DOMAIN_TO_TYPE;
// ...
var _c;
$RefreshReg$(_c, "MODULE_DOMAIN_TO_TYPE");

So that $RefreshReg$ is not available inside a Worker. Which makes sense. What doesn't make sense is that the plugin is trying to consider the MODULE_DOMAIN_TO_TYPE value a component.

Reproduction

N/A

Steps to reproduce

I tried to create a reproduction on StackBlitz but it didn't work to set up the oxc versions of Vite+Rolldown+vite-plugin-react with overrides for Vite.

The repro would be to import a shared library module from a Worker.

System Info

System:
    OS: macOS 15.5
    CPU: (16) arm64 Apple M3 Max
    Memory: 2.49 GB / 128.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.2.0 - /opt/homebrew/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn
    npm: 11.3.0 - /opt/homebrew/bin/npm
    bun: 1.2.5 - ~/.bun/bin/bun
  Browsers:
    Chrome: 137.0.7151.119
    Safari: 18.5

Used Package Manager

bun

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions