1. 程式人生 > 實用技巧 >react-create-app 新增 less/解決 npm run eject報錯

react-create-app 新增 less/解決 npm run eject報錯

想要新增less 需要暴露 webpack.config 配置檔案 先開啟專案根目錄命令列執行 npm run eject:執行之後,我們發現多了一個config資料夾

如果執行後 點選y/n 確認(y),報錯了:報錯資訊為:

Remove untracked files, stash or commit any changes, and try again.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test@0.1.0 eject: `react-scripts eject`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the test@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:

那麼時因為 腳手架新增.gitgnore檔案,但是卻沒有本地倉庫,(或者時有本地倉庫沒有初始化 init)
只要按順序 執行下git 提交 再執行npm run eject 即可
create-react-app test//不是必須如果開啟原有專案可以忽略
cd test//不是必須如果開啟原有專案可以忽略
1:git init 
2:git add .
3:git commit -m '描述說明'
4:npm run eject