react踩坑

yarn run eject时

Remove untracked files, stash or commit any changes, and try again.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] eject: `react-scripts eject`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] 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踩坑)