记录贴,根据遇到的问题记录解决方法,以便查阅。
1、react-app-rewired' 不是内部或外部命令,也不是可运行的程序
启动react的时候,执行npm start出现:
'react-app-rewired' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! reactdemo@0.1.0 start: `react-app-rewired start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the reactdemo@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\AppData\Roaming\npm-cache\_logs\2019-12-08T09_32_15_462Z-debug.log
解决方法:这可能是create-react-app有丢包的缺陷,手动安装包后,需要重新npm install一下,这样node_modules/.bin/目录下才会重新出现react-scripts的文件,这样npm start命令才能正常执行。
npm install 或 npm install react-scripts
2、Warning: validateDOMNesting(...): <tr> cannot appear as a child of <table>
在react中<tr>元素不可作为<table>元素的直接子元素。
解决方法:在<tr>和<table>直接加上<tbody>元素。
<table>
<tbody>
<tr>
<td></td>
</tr>
<tbody>
</table>
3、Error: link is a void element tag and must neither have children
nor use dangerouslySetInnerHTML
。
这个问题是在react的<Router></Router>标签中使用link出现的错误,如下:
<link to="/">页面</link><br/>
解决方法:这个错误的原因是link标签写错了,应该写成<Link></Link>,L需要大写,这个Link是react-router中的。
写在最后:
- 如果文章中有错误或是表达不准确的地方,欢迎大家评论中指正,以便我完善。
- 文章我也会根据所学到新的知识不断更新。
网友评论