問題特徵

在使用yarn或者npm過程中,嘗試添加包(或者直接通過install添加package.json中所有包時)最後一步報錯,提示無許可權之類的信息。

$ yarn add webpackyarn add v1.6.0warning package.json: No license fieldwarning No license field[1/4] Resolving packages...[2/4] Fetching packages...info [email protected]: The platform "linux" is incompatible with this module.info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.[3/4] Linking dependencies...error An unexpected error occurred: "ENOTSUP: operation not supported on socket, symlink ../../../acorn/bin/acorn -> /mnt/hgfs/workspace/temp/nodetest/node_modules/acorn-dynamic-import/node_modules/.bin/acorn".info If you think this is a bug, please open a bug report with the information provided in "/mnt/hgfs/workspace/temp/nodetest/yarn-error.log".info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

解決方案

全局啟用no-bin-link選項即可

對於yarn,在~/.yarnrc中添加

"--*.no-bin-links" true

對於npm

config | npm Documentation?

docs.npmjs.com

我早就不用npm了,我不知道怎麼配置

問題出現的原因

vmhgfs(應用於VMWare共享文件夾的Linux端vfs)不支持symlink(或者可能是不支持Linux和Windows下的符號鏈接格式互相轉換)。

這個問題其實我已經折騰很久了,最開始我的解決思路是使用其他方式去代替vmhgfs,比如nfs和cifs(smb)。nfs性能太低,cifs也不支持symlink,一直都沒有完美的,後來調轉思路發現其實通過這樣去禁用yarn(npm)的符號鏈接創建也可以。

但是這樣並沒有完全解決vmhgfs不支持symlink這個問題,好在日常中很少需要在共享文件夾中創建符號鏈接。

這樣設置暫時沒有發現其他問題。


推薦閱讀:
相關文章