mobxjs/mobx · critical

mobx-react requires React to be available

Error message

mobx-react requires React to be available

What it means

mobx-react checks at import time that React's `Component` class is importable; if `react` failed to load or resolved to an empty module, `Component` is undefined and this error throws immediately. It guards against importing mobx-react without a working React installation.

Source

Thrown at packages/mobx-react/src/index.ts:5

import { observable } from "mobx"
import { Component } from "react"

if (!Component) {
    throw new Error("mobx-react requires React to be available")
}

if (!observable) {
    throw new Error("mobx-react requires mobx to be available")
}

export {
    Observer,
    isUsingStaticRendering,
    enableStaticRendering,
    useLocalObservable,
    _observerFinalizationRegistry,
    clearTimers
} from "mobx-react-lite"

export { observer } from "./observer"

View on GitHub (pinned to 01211a698b)

Solutions

  1. Install React: `npm install react` and confirm it is in package.json dependencies.
  2. Inspect the resolved `react` module (console.log in node_modules or bundler stats) — fix any alias resolving react to an empty object.
  3. Remove mobx-react import from code paths that should run without React (e.g. pure server code) and depend on `mobx` directly.

Example fix

// before
$ node server.js // Error: mobx-react requires React to be available

// after
$ npm install react react-dom
Defensive patterns

Strategy: validation

Validate before calling

import * as React from 'react'
if (!React.Component) {
  throw new Error('react is not resolving correctly; check installation/aliases before importing mobx-react')
}

Type guard

const hasReactComponent = (R) => typeof R?.Component === 'function'

Prevention

When it happens

Trigger: Importing mobx-react in a Node/server environment where `react` is not installed or is aliased to an empty stub; broken bundler resolution returning an empty module for 'react'.

Common situations: Running a bundle in Node without react in dependencies; jest moduleNameMapper or webpack alias stubbing react; SSR setups where react is externalized but missing at runtime.

Related errors


AI-assisted analysis of mobxjs/mobx@01211a698b (2026-08-28). Data as JSON: /api/errors/a61365314769b58b. Report an issue: GitHub.