{"record":{"id":"30889bfd979e433b","repo":"mobxjs/mobx","slug":"mobx-react-requires-mobx-to-be-available","errorCode":null,"errorMessage":"mobx-react requires mobx to be available","messagePattern":"mobx-react requires mobx to be available","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"packages/mobx-react/src/index.ts","lineNumber":9,"sourceCode":"import { observable } from \"mobx\"\nimport { Component } from \"react\"\n\nif (!Component) {\n    throw new Error(\"mobx-react requires React to be available\")\n}\n\nif (!observable) {\n    throw new Error(\"mobx-react requires mobx to be available\")\n}\n\nexport {\n    Observer,\n    isUsingStaticRendering,\n    enableStaticRendering,\n    useLocalObservable,\n    _observerFinalizationRegistry,\n    clearTimers\n} from \"mobx-react-lite\"\n\nexport { observer } from \"./observer\"\n","sourceCodeStart":1,"sourceCodeEnd":22,"githubUrl":"https://github.com/mobxjs/mobx/blob/01211a698b64ea94de8e5f276ff8235fcf8ddf96/packages/mobx-react/src/index.ts#L1-L22","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Install mobx: `npm install mobx` and add it to package.json dependencies.","Check bundler aliases/externals for 'mobx' and make sure it resolves to the real installed package.","Run `npm ls mobx` to verify a single mobx copy is installed and accessible from the importing package."],"exampleFix":"// before (package.json)\n\"mobx-react\": \"^8.0.0\" // mobx missing\n\n// after\n\"mobx\": \"^7.0.0\",\n\"mobx-react\": \"^8.0.0\"","handlingStrategy":"validation","validationCode":"import { observable } from 'mobx'\nif (!observable) {\n  throw new Error('mobx is not resolving correctly; install/alias mobx before importing mobx-react')\n}","typeGuard":"const hasMobxObservable = (m) => typeof m?.observable === 'function'","tryCatchPattern":null,"preventionTips":["Add mobx as an explicit dependency wherever mobx-react is used; never rely on hoisting.","Check bundler externals/aliases for 'mobx' misconfiguration.","Run `npm ls mobx` to confirm a single accessible copy.","Add an import smoke test to CI builds."],"tags":["mobx","mobx-react","missing-dependency","module-resolution"],"backgroundTag":"missing-mobx-installation","analyzedSha":"01211a698b64ea94de8e5f276ff8235fcf8ddf96","analyzedAt":"2026-08-28T22:10:08.831Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}