{"record":{"id":"a61365314769b58b","repo":"mobxjs/mobx","slug":"mobx-react-requires-react-to-be-available","errorCode":null,"errorMessage":"mobx-react requires React to be available","messagePattern":"mobx-react requires React to be available","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"packages/mobx-react/src/index.ts","lineNumber":5,"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":"mobx-react checks at import time that React's `Component` class is importable; if `react` failed to load or resolved to an empty module, `Component` is undefined and this error throws immediately. It guards against importing mobx-react without a working React installation.","triggerScenarios":"Importing mobx-react in a Node/server environment where `react` is not installed or is aliased to an empty stub; broken bundler resolution returning an empty module for 'react'.","commonSituations":"Running a bundle in Node without react in dependencies; jest moduleNameMapper or webpack alias stubbing react; SSR setups where react is externalized but missing at runtime.","solutions":["Install React: `npm install react` and confirm it is in package.json dependencies.","Inspect the resolved `react` module (console.log in node_modules or bundler stats) — fix any alias resolving react to an empty object.","Remove mobx-react import from code paths that should run without React (e.g. pure server code) and depend on `mobx` directly."],"exampleFix":"// before\n$ node server.js // Error: mobx-react requires React to be available\n\n// after\n$ npm install react react-dom","handlingStrategy":"validation","validationCode":"import * as React from 'react'\nif (!React.Component) {\n  throw new Error('react is not resolving correctly; check installation/aliases before importing mobx-react')\n}","typeGuard":"const hasReactComponent = (R) => typeof R?.Component === 'function'","tryCatchPattern":null,"preventionTips":["Ensure react is a direct dependency of every package that imports mobx-react.","Verify webpack/jest aliases map 'react' to the real installed build, not a stub.","Keep mobx-react imports out of non-React code paths (pure server/store modules).","Run a minimal import smoke test in CI on the production bundle."],"tags":["react","mobx-react","missing-dependency","environment","module-resolution"],"backgroundTag":"missing-react-installation","analyzedSha":"01211a698b64ea94de8e5f276ff8235fcf8ddf96","analyzedAt":"2026-08-28T22:10:08.831Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}