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
- Install React: `npm install react` and confirm it is in package.json dependencies.
- Inspect the resolved `react` module (console.log in node_modules or bundler stats) — fix any alias resolving react to an empty object.
- 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
- Ensure react is a direct dependency of every package that imports mobx-react.
- Verify webpack/jest aliases map 'react' to the real installed build, not a stub.
- Keep mobx-react imports out of non-React code paths (pure server/store modules).
- Run a minimal import smoke test in CI on the production bundle.
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
- mobx-react requires mobx to be available
- mobx-react-lite requires React 18 or later
- [mobx-react-lite] You are trying to use `observer` on a func
- [mobx-react-lite] `render` property of ForwardRef was not a
- The provided component class (${displayName}) has already be
AI-assisted analysis of mobxjs/mobx@01211a698b (2026-08-28).
Data as JSON: /api/errors/a61365314769b58b.
Report an issue: GitHub.