Skip to content
← Back to rules

react/invariant Restriction

What it does

Reports internal React Compiler invariant violations. These indicate a bug in the compiler itself, not in your code — consider reporting them to the oxc or React teams.

Powered by the React Compiler, which runs once per file and is shared with the other React Compiler rules. Port of react-hooks/invariant.

Why is this bad?

An invariant violation means the compiler's internal state is inconsistent; the affected function is skipped rather than optimized.

How to use

To enable this rule using the config file or in the CLI, you can use:

json
{
  "plugins": ["react"],
  "rules": {
    "react/invariant": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["react"],
  rules: {
    "react/invariant": "error",
  },
});
bash
oxlint --deny react/invariant --react-plugin

Version

This rule was added in vnext.

References