{"record":{"id":"9caffb18a0ff10a6","repo":"mobxjs/mobx","slug":"mobx-react-lite-requires-mobx-at-least-version-7-t","errorCode":null,"errorMessage":"mobx-react-lite requires mobx at least version 7 to be available","messagePattern":"mobx-react-lite requires mobx at least version 7 to be available","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"packages/mobx-react-lite/src/utils/assertEnvironment.ts","lineNumber":8,"sourceCode":"import { _getGlobalState } from \"mobx\"\nimport { useState, useSyncExternalStore } from \"react\"\n\nif (!useState || !useSyncExternalStore) {\n    throw new Error(\"mobx-react-lite requires React 18 or later\")\n}\nif (!(_getGlobalState?.()?.version >= 7)) {\n    throw new Error(\"mobx-react-lite requires mobx at least version 7 to be available\")\n}\n","sourceCodeStart":1,"sourceCodeEnd":10,"githubUrl":"https://github.com/mobxjs/mobx/blob/01211a698b64ea94de8e5f276ff8235fcf8ddf96/packages/mobx-react-lite/src/utils/assertEnvironment.ts#L1-L10","documentation":"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.","triggerScenarios":"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.","commonSituations":"Upgrading mobx-react-lite without upgrading mobx; monorepo/lockfile conflicts leaving mobx@6 in node_modules; transitive dependencies pinning mobx 6.","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."],"exampleFix":"// before (package.json)\n\"mobx\": \"^6.6.0\",\n\"mobx-react-lite\": \"^4.0.0\"\n\n// after\n\"mobx\": \"^7.0.0\",\n\"mobx-react-lite\": \"^4.0.0\"","handlingStrategy":"validation","validationCode":"import { _getGlobalState } from 'mobx'\nif (!(_getGlobalState?.()?.version >= 7)) {\n  throw new Error('Install mobx@>=7 before using mobx-react-lite')\n}","typeGuard":"const isMobx7Plus = (mobx) => Number(mobx?._getGlobalState?.()?.version ?? 0) >= 7","tryCatchPattern":"try {\n  require('mobx-react-lite')\n} catch (e) {\n  if (String(e.message).includes('mobx at least version 7')) {\n    // run `npm ls mobx` and dedupe/upgrade mobx\n  }\n  throw e\n}","preventionTips":["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."],"tags":["mobx","mobx-react-lite","version-compatibility","duplicate-dependency"],"backgroundTag":"mobx-version-too-old","analyzedSha":"01211a698b64ea94de8e5f276ff8235fcf8ddf96","analyzedAt":"2026-08-28T22:10:08.831Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}