每当我做一个npm run watch时,我都会收到此警告:
WARNING in react-profile-page.1.0.0.min.js from UglifyJs
Side effects in initialization of unused variable React [./js/index.js:3,4]
Side effects in initialization of unused variable ReactDOM [./js/index.js:4,4]
Condition always true [./~/react/lib/traverseAllChildren.js:136,0]
Condition always true [./~/react/lib/ReactDOMComponentTree.js:97,0]
Condition always true [./~/react/lib/ReactDOMComponent.js:982,0]
Condition always true [./~/react/lib/ReactMultiChild.js:265,0]
Condition always true [./~/react/lib/ReactMultiChild.js:285,0]
Condition always true [./~/react/lib/instantiateReactComponent.js:91,0]
Condition always true [./~/react/lib/ReactNodeTypes.js:36,0]
Side effects in initialization of unused variable Transaction [./~/react/lib/ReactServerUpdateQueue.js:18,0]
Condition always true [./~/react/lib/findDOMNode.js:54,0]
Condition always true [./~/react/lib/findDOMNode.js:56,0]
我在网上阅读的所有地方似乎都告诉我,无论何时我尝试在浏览器上运行HTML页面,都应该忽略这些警告:
<!doctype HTML>
<html>
<head>
<title>First React Page</title>
<!--remember to change the name of your build files and match them here-->
<link rel="stylesheet" href="react-profile-page.1.0.0.css">
</head>
<body>
<div id="app"></div>
</body>
<script src="react-profile-page.1.0.0.js"></script>
</html>
我只是得到一个空白的屏幕,这意味着我在index.js中创建的反应元素没有被读取。所以这个警告必须是原因,对吧?
这是index.js:
"use strict"
var React = require('react');
var ReactDOM = require('react-dom');
var Person = function() {
var name = 'Derek Zoolander';
var imageUrl = 'http://uifaces.com/assets/static/images/zoolander.jpg';
var job = 'Male model';
return (
<div className="person">
<div className="person-name">{name}</div>
<img className="person-img" src={imageUrl} />
<div className="person-job">
{job}
</div>
</div>
);
};
document.addEventListener('DOMContentLoaded', function() {
ReactDOM.render(<Person />, document.getElementById('app'));
});
我只是得到一个空白的屏幕,这意味着我在index.js中创建的反应元素没有被读取。所以这个警告一定是为什么,对吧?我试图摆脱“使用严格”并消除了前两个警告,但仍未在浏览器中加载。