{"record":{"id":"5b22ad8b35333dc7","repo":"facebook/react","slug":"react-cache-unsupported-react-version","errorCode":null,"errorMessage":"react-cache: Unsupported React version","messagePattern":"react-cache: Unsupported React version","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/react-devtools-shared/src/devtools/cache.js","lineNumber":66,"sourceCode":"} else if (\n  typeof (React as any).__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED ===\n  'object'\n) {\n  const ReactCurrentDispatcher = (React as any)\n    .__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher;\n  readContext = function (Context: ReactContext<null>) {\n    const dispatcher = ReactCurrentDispatcher.current;\n    if (dispatcher === null) {\n      throw new Error(\n        'react-cache: read and preload may only be called from within a ' +\n          \"component's render. They are not supported in event handlers or \" +\n          'lifecycle methods.',\n      );\n    }\n    return dispatcher.readContext(Context);\n  };\n} else {\n  throw new Error('react-cache: Unsupported React version');\n}\n\nconst CacheContext = createContext(null);\n\ntype Config = {useWeakMap?: boolean, ...};\n\nconst entries: Map<\n  Resource<any, any, any>,\n  Map<any, any> | WeakMap<any, any>,\n> = new Map();\nconst resourceConfigs: Map<Resource<any, any, any>, Config> = new Map();\n\nfunction getEntriesForResource(\n  resource: any,\n): Map<any, any> | WeakMap<any, any> {\n  let entriesForResource: Map<any, any> | WeakMap<any, any> = entries.get(\n    resource,\n  ) as any as Map<any, any>;","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-devtools-shared/src/devtools/cache.js#L48-L84","documentation":"At module load, react-devtools-shared's cache probes the host React for either React.use (React 19+) or __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher (React 16.6–18) to implement readContext. If neither exists it throws 'react-cache: Unsupported React version' while the module is being imported, taking the whole DevTools bundle down with it.","triggerScenarios":"Importing react-devtools-shared (or anything that pulls in devtools/cache) in an environment whose 'react' module exposes neither React.use nor the secret-internals object — e.g. React < 16.6, a jest.mock('react') stub, or a React-mocking shim in tests.","commonSituations":"Unit tests that mock 'react' without preserving internals; resolving a different/older React duplicate than the one devtools was built against; embedding DevTools packages into an app pinned to an old React.","solutions":["Upgrade the host react/react-dom to 16.8+ (or 19+ for the React.use path).","Hunt duplicates: npm ls react / yarn why react, and make devtools resolve the same React copy the app uses.","Fix test mocks: jest.mock('react') with requireActual, so __SECRET_INTERNALS survive."],"exampleFix":"// before — package.json\n\"react\": \"^15.6.0\"\n\n// after\n\"react\": \"^18.3.1\"","handlingStrategy":"validation","validationCode":"function supportsDevToolsCache(React) {\n  return (\n    typeof React.use === 'function' ||\n    (React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED != null &&\n      React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher != null)\n  );\n}\nif (!supportsDevToolsCache(require('react'))) {\n  throw new Error('Upgrade React to 16.8+ before loading DevTools');\n}","typeGuard":"function supportsDevToolsCache(React) {\n  return (\n    typeof React.use === 'function' ||\n    (React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED != null &&\n      React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher != null)\n  );\n}","tryCatchPattern":null,"preventionTips":["Pin react/react-dom >= 16.8 wherever react-devtools-shared is imported.","Dedupe React copies so devtools resolves the app's React.","In jest, mock react with requireActual so secret internals survive."],"tags":["devtools","react-version","compatibility","module-init"],"backgroundTag":"unsupported-react-version","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}