mobxjs/mobx · critical

mobx-react requires mobx to be available

Error message

mobx-react requires mobx to be available

What it means

Symmetric to the React check: mobx-react verifies `observable` from mobx is importable at load time and throws if mobx is missing or resolved to an empty module. It ensures mobx is properly installed and loadable before any mobx-react feature is used.

Source

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

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 mobx: `npm install mobx` and add it to package.json dependencies.
  2. Check bundler aliases/externals for 'mobx' and make sure it resolves to the real installed package.
  3. Run `npm ls mobx` to verify a single mobx copy is installed and accessible from the importing package.

Example fix

// before (package.json)
"mobx-react": "^8.0.0" // mobx missing

// after
"mobx": "^7.0.0",
"mobx-react": "^8.0.0"
Defensive patterns

Strategy: validation

Validate before calling

import { observable } from 'mobx'
if (!observable) {
  throw new Error('mobx is not resolving correctly; install/alias mobx before importing mobx-react')
}

Type guard

const hasMobxObservable = (m) => typeof m?.observable === 'function'

Prevention

When it happens

Trigger: Importing mobx-react without mobx installed; bundler/alias mapping 'mobx' to a stub or empty module; circular import or build misconfiguration causing the mobx import to yield undefined.

Common situations: Forgetting to add mobx to a new package in a monorepo (relying on hoisting); webpack externals misconfigured for mobx; a build tool tree-shaking mobx exports incorrectly.

Related errors


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