You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React项目出现'ReactCurrentOwner'未定义TypeError报错求助

Hey there, let's work through that TypeError: Cannot read property 'ReactCurrentOwner' of undefined error you're seeing. After digging into your code, dependencies, and setup, here are the root issues and straightforward fixes:

1. React/ReactDOM Version Mismatch & Duplicate React Copies

This is the biggest culprit here:

  • Your package.json lists react-dom as version 2.2.2—that's extremely outdated and completely incompatible with your react@15.6.1 installation. React and ReactDOM must always share the same major/minor version to work together properly.
  • You're also loading two separate instances of React: one from your local npm install, and another from the CDN scripts in your HTML. This creates a conflict where React's internal variables (like ReactCurrentOwner) aren't accessible across the mismatched copies.

Fix Steps:

  • Update react-dom in your package.json to match React's version:
    "react-dom": "15.6.1"
    
  • Remove the two CDN script tags from your HTML file. Your webpack build will bundle React and ReactDOM into your app automatically, so these external copies are redundant and harmful.

2. Typo in Babel Preset Version

Your babel-preset-env has a typo in the version number (1.5,2 instead of 1.5.2). This can cause broken transpilation, which might lead to unexpected issues with React's internal code.

Fix:

Correct the version in package.json:

"babel-preset-env": "1.5.2"

3. Refresh Dependencies & Rebuild

After fixing the above, you need to clean up and rebuild to ensure everything is synced:

  • Run yarn install again to pull the correct versions of ReactDOM and babel-preset-env.
  • Delete your existing build output (usually public/bundle.js or similar) to get rid of any leftover old code.
  • Run yarn build to create a fresh bundle, then yarn serve to start your app.

Quick Note on Component Code

While it's not causing your current error, I spotted a small outdated pattern in your handleAddOption method: you're using var len = 0;. Since you're using React classes and modern JS, switching to let (or const if the value doesn't change) would be more consistent, but this is optional for now.

Once you apply these fixes, the ReactCurrentOwner error should disappear, and your Indecision app should run like it did before adding the new feature.

内容的提问来源于stack exchange,提问作者Nishanth Reddy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:52:18