Reactjs React JS初学者程序错误
有人能帮我在Sublime开始一个新的简单项目吗。。 这是我的index.jsReactjs React JS初学者程序错误,reactjs,Reactjs,有人能帮我在Sublime开始一个新的简单项目吗。。 这是我的index.js import React, {Component} from 'react'; import ReactDOM from 'react-dom'; class Blog extends Component { render(){ const sidebar = ( <ul> {this.props.posts.map((post) => <li
import React, {Component} from 'react';
import ReactDOM from 'react-dom';
class Blog extends Component {
render(){
const sidebar = (
<ul>
{this.props.posts.map((post) =>
<li key={post.id}>
{post.title}
</li>
)}
</ul>
);
const content = this.props.posts.map((post) =>
<div key={post.id}>
<h3>{post.title}</h3>
<p>{post.content}</p>
</div>
);
return (
<div>
{sidebar}
<hr />
{content}
</div>
);
}
}
const posts = [
{id: 1, title: 'Hello World', content: 'Welcome to learning React!'},
{id: 2, title: 'Installation', content: 'You can install React from npm.'}
];
ReactDOM.render(
<Blog posts={posts}
/>,
document.getElementById('root')
);
运行这个项目需要什么东西吗。。
我试图通过安装react、reactdom等来运行这个项目cmd,然后通过npmi安装npm。然后我试着运行项目我的npm运行开始
在cmd中
> mypro@1.0.0 start E:\Projects\MyPro
> react-scripts start
Could not find a required file.
Name: index.html
Searched in: E:\Projects\MyPro\public
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\
node_modules\\npm\\bin\\npm-cli.js" "run" "start"
npm ERR! node v7.10.1
npm ERR! npm v4.2.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mypro@1.0.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the mypro@1.0.0 start script 'react-scripts start'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the mypro package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! react-scripts start
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs mypro
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls mypro
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\keystrokeslnc08\AppData\Roaming\npm-cache\_logs\2018-03-15
T08_39_46_854Z-debug.log
这是我的索引。html页面
<!DOCTYPE html>
<html lang="en">
<head>
<title>MyProject</title>
</head>
<body>
<h1>hlo everyone</h1>
<div id="app"></div>
<script src="/bundle.js"></script>
</body>
</html>
我的项目
大家好
此错误显示。。接下来我要做什么???您应该在package.json中将react脚本作为devdependences
{
"name": "mypro",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "react-scripts start",
"build": "react-scripts build"
},
"author": "",
"license": "ISC",
"dependencies": {
"babel": "^6.23.0",
"babel-cli": "^6.26.0",
"eslint": "^4.18.2",
"react": "^16.2.0",
"react-dom": "^16.2.0"
},
"devDependencies": {
"react-scripts": "^1.1.1"
}
}
npm install --save-dev react-scripts
应该更好启动简单项目的最佳方式 首先安装nodejs(您需要一台服务器在本地运行您的应用程序) 打开命令提示符 1:npm安装-g创建反应应用程序 2:创建react应用程序您的应用程序名称 转到目录路径(例如:cd您的应用程序名称) 最后:npm开始
就是这样尝试npm安装--保存开发反应脚本这里是添加在下面的
index.html
?@BoyWithSilverWings,文件路径。对不起,我不明白你的意思。可以解释您的实际意思吗?react脚本是否出现在您的package.json上?是的,请参阅上面的包代码,我在安装react脚本后对其进行了编辑。。我还编辑了cmd屏幕。。。新错误现在出现在cmd上