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
- Upgrade mobx to 7 or later (`npm install mobx@latest`).
- Run `npm ls mobx` (or yarn why) to find duplicate versions and dedupe; delete stale lockfile entries and reinstall.
- Add a package override/resolution forcing a single mobx 7+ version across all transitive dependencies.
- 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
- Upgrade mobx and mobx-react-lite together in one commit.
- Run `npm ls mobx` in CI to detect duplicate/stale mobx copies.
- Use package overrides/resolutions to force one mobx version for transitive deps.
- Regenerate the lockfile after major mobx upgrades.
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
- 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
- mobx-react requires mobx to be available
- [mobx-react] Cannot read "${admin.name}.${key}" in a reactiv
AI-assisted analysis of mobxjs/mobx@01211a698b (2026-08-28).
Data as JSON: /api/errors/9caffb18a0ff10a6.
Report an issue: GitHub.