ReactDom未定义

时间:2016-04-12 14:55:56

标签: javascript reactjs webpack babeljs react-dom

我正在使用React与Webpack和Babel。我收到运行时错误:

  

未捕获的ReferenceError:未定义ReactDom

我的反应版本是:

"devDependencies": {
   "phantomjs-polyfill": "0.0.2",
   "react-addons-test-utils": "^0.14.8"
 },    
 "dependencies": {
   "react": "^0.14.7",
   "react-dom": "^0.14.7"
 },

我的代码是:

import React from 'react';
import ReactDOM from 'react-dom';
import Main from './components/main';

ReactDom.render(<Main />, document.getElementById('root'));

我做错了什么?

3 个答案:

答案 0 :(得分:31)

您有JPanel但是您没有Thread (区分大小写)

ReactDOM

答案 1 :(得分:1)

ReactDOM != ReactDom。您可以通过两件事来解决此问题。

import React from 'react';
import ReactDOM from 'react-dom'; // you used 'react-dom' as 'ReactDOM'
import Main from './components/main';

ReactDom.render(<Main />, document.getElementById('root')); // you referred to it as 'ReactDom' which is wrong.

因为ReactDOM!= ReactDom。因此,您需要修复其中一个位置,以便两个位置的名称相同且大小写相同。

建议的解决方法是

import React from 'react';
import ReactDOM from 'react-dom'; // this is recommended 
import Main from './components/main';

ReactDOM.render(<Main />, document.getElementById('root'));

或者你可以做,

import React from 'react';
import ReactDom from 'react-dom';
import Main from './components/main';

ReactDom.render(<Main />, document.getElementById('root'));

答案 2 :(得分:-1)

只需将ReactDom(在Dom中,om用小写形式)替换为ReactDOM(请注意,您需要用大写形式写OM),您的问题将会得到解决。