美文网首页
react踩坑

react踩坑

作者: 哎乌勒 | 来源:发表于2018-12-13 17:06 被阅读0次

yarn run eject时

Remove untracked files, stash or commit any changes, and try again.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! devportalfrontend@0.1.0 eject: `react-scripts eject`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the devportalfrontend@0.1.0 eject 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!     /home/deep/.npm/_logs/2018-02-18T17_05_02_924Z-debug.log

Uninstalling react-scripts and installing react-scripts-cssmodules solved the problem

npm uninstall react-scripts
npm install react-scripts-cssmodules
 npm run eject

运行第一个命令时报错,权限错误,关闭后用管理员模式打开运行

git add .

git commit -am "Save before ejecting"

成功

代码问题

1.图片img路径问题


将图片名称当做参数传入.png
获取参数,将选中图片地址保存在state中.png
在img中获取图片地址

运行报错


报错.png
require后的()中接收的是string类型,可能state保存的是object类型
解决方法:将require一起存入state中
handleOpen=(img)=>{
        this.setState({
            visible:true,
            currentImg:require('../../resource/assets/img/gallery/'+img),
        })
    }

4.commit时报错

pre-commit的报错

解决:删除.git里的pre-commit文件,不是万全之策,尝试其他解决办法

相关文章

网友评论

      本文标题:react踩坑

      本文链接:https://www.haomeiwen.com/subject/jfuncqtx.html