背景
最近用create-react-app構(gòu)建react項(xiàng)目過程中,使用官方推薦的方法處理scss文件的編譯問題,即node-sass-chokidar,編輯器使用VSCode,在修改scss文件并保存的過程中,出現(xiàn)編譯失敗的問題,報錯內(nèi)容為File to read not found or unreadable,具體如下
{
"status": 3,
"message": "File to read not found or unreadable: E:/learn/react-app1/src/index.scss",
"formatted": "Internal Error: File to read not found or unreadable: E:/learn/react-app1/src/index.scss\n"
}
解決
直接上github的Issue找,這種問題一般不會是個人問題,果不其然,發(fā)現(xiàn)了相關(guān)的Issue,一步一步跟進(jìn)最終找到了解決方法,在node-sass項(xiàng)目的Issue下,解決要點(diǎn):
- 由
marcosbozzani大神做了修復(fù),修復(fù)分支bug-vscode-watch - 此時node-sass最新版本為
4.9,版本中未處理此問題 - 需要手動修復(fù),替換
node_modules/node-sass/lib/render.js為render.js
此問題并不是node-sass的問題,主要是vscode鎖定了文件而造成了文件不可讀,marcosbozzani大神是這么說的The problem seems to be VSCode is still holding the file while node-sass try to access it.
在此記錄一下問題及解決方法,分享給有需要的朋友