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

验证过上面的方法确实有效,不过最终解决问题仍是要等微软更新版本。

相关文章
相关标签/搜索