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! 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路徑問題


將圖片名稱當做參數(shù)傳入.png

獲取參數(shù),將選中圖片地址保存在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文件,不是萬全之策,嘗試其他解決辦法

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容