WSL中使用NPM和yarn

從Windows 10 1709版本開始,WSL(Windows Subsystem for Linux)已經成爲自帶的功能,具體安裝方式能夠參考https://juejin.im/entry/59ed4...node

對於習慣使用Linux運行程序,可是開發時候喜歡windows的程序員來說,WSL是最好的選擇了。奈何WSL有不少bug,常常會出現一些奇怪的事情,百思不得其解的時候發現問題仍是在WSL中,例如,在1709版本中使用npm或者yarn安裝包依賴時,會出現各類問題:
例如在yarn中,出現了一下的問題:linux

$ yarn
[1/4] Resolving packages...
error An unexpected error occurred: "EINVAL: invalid argument, lstat '/mnt/c/Users/duybui/code/web/old/node_modules/accord/node_modules/cliui/README.md'".
info If you think this is a bug, please open a bug report with the information provided in "/mnt/c/Users/duybui/code/web/old/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

從上面的錯誤日誌中能夠發現一個EINVAL: invalid argument, lstat 錯誤,這個錯誤是什麼意思?
首先咱們查看一下lstat命令是幹嗎用的:git

These functions return information about a file. No permissions are required on the file itself, but-in the case of stat() and lstat() - execute (search) permission is required on all of the directories in path that lead to the file.

from: https://linux.die.net/man/2/lstat

從上面的描述來看,這是一個文件系統的錯誤,獲取文件信息的時候出錯了。程序員

爲何會出現文件系統級別的錯誤???????????github

微軟的程序員出來解釋說:web

Hi all. I've been pinged several times over the last 48 hours for an update on the fix for this issue.

Know that we appreciate and understand the enthusiasm for the fix for this issue, but we do ask for your patience as the fix makes its way up through our build and test systems, on its way to the Insider rings.

As @SvenGroot stated above, the fix has been checked in but it didn't make it up to the Insider release branch in time for 17025 which was released on 11/1. It's v. likely it'll arrive in the next Insider build.

Sven is also working to backport this fix to Fall Creators Update (FCU), but since this isn't a fix for a major security exploit, it'll make its way through our normal servicing channels, passing through numerous review and testing gates before it's formally released in an up-coming servicing release.

Please note...

講了一大堆,其實就是說:「咱們已經知道這個錯誤了,可是短時間內不會立刻修復,請關注咱們的進度。」
真是使人失望,連問題的根本緣由也沒有告訴咱們。npm

不過熱心的網友仍是提供了一個奇妙的方法:
~/.bashrc中增長以下代碼:windows

# Workaround for issue: https://github.com/Microsoft/WSL/issues/2448
if ! mount | grep -q "C: on /mnt/c type drvfs (rw,noatime,fallback=1)"; then
        echo "== Remount of C: drive required =="
        pushd ~ > /dev/null
        sudo umount /mnt/c
        sudo mount -t drvfs -o noatime,fallback=1 C: /mnt/c
        popd > /dev/null
fi

從上面的代碼來看,就是umount了C盤,而後從新Mount上去,只是增長了一些參數:
首先是drvfs微軟的一篇博客對它進行了比較詳細的講解:https://blogs.msdn.microsoft....bash

-o noatime是提升文件系統性能的一個參數,禁止記錄最近一次訪問時間戳,至於fallback=1就不太理解了。app

驗證過上面的方法確實有效,不過最終解決問題仍是要等微軟更新版本。

相關文章
相關標籤/搜索