mobxjs/mobx · critical

mobx-react-lite requires mobx at least version 7 to be avail

Error message

mobx-react-lite requires mobx at least version 7 to be available

What it means

mobx-react-lite requires mobx 7+; it checks `_getGlobalState().version >= 7` at module load and throws if the installed/first-loaded mobx copy is older. Typically the installed mobx is 6.x or below, or two mobx copies exist and a stale one wins module resolution.

Source

Thrown at packages/mobx-react-lite/src/utils/assertEnvironment.ts:8

import { _getGlobalState } from "mobx"
import { useState, useSyncExternalStore } from "react"

if (!useState || !useSyncExternalStore) {
    throw new Error("mobx-react-lite requires React 18 or later")
}
if (!(_getGlobalState?.()?.version >= 7)) {
    throw new Error("mobx-react-lite requires mobx at least version 7 to be available")
}

View on GitHub (pinned to 01211a698b)

Solutions

  1. Upgrade mobx to 7 or later (`npm install mobx@latest`).
  2. Run `npm ls mobx` (or yarn why) to find duplicate versions and dedupe; delete stale lockfile entries and reinstall.
  3. Add a package override/resolution forcing a single mobx 7+ version across all transitive dependencies.
  4. If you must stay on mobx 6, use mobx-react-lite 3.x which is compatible with mobx 6.

Example fix

// before (package.json)
"mobx": "^6.6.0",
"mobx-react-lite": "^4.0.0"

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

Strategy: validation

Validate before calling

import { _getGlobalState } from 'mobx'
if (!(_getGlobalState?.()?.version >= 7)) {
  throw new Error('Install mobx@>=7 before using mobx-react-lite')
}

Type guard

const isMobx7Plus = (mobx) => Number(mobx?._getGlobalState?.()?.version ?? 0) >= 7

Try / catch

try {
  require('mobx-react-lite')
} catch (e) {
  if (String(e.message).includes('mobx at least version 7')) {
    // run `npm ls mobx` and dedupe/upgrade mobx
  }
  throw e
}

Prevention

When it happens

Trigger: Importing mobx-react-lite (latest) with mobx 6.x installed; duplicate mobx versions in node_modules where an old copy is hoisted; a dependency bundling mobx 6 internally.

Common situations: Upgrading mobx-react-lite without upgrading mobx; monorepo/lockfile conflicts leaving mobx@6 in node_modules; transitive dependencies pinning mobx 6.

Related errors


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