{"id":3571,"date":"2019-05-30T22:25:35","date_gmt":"2019-05-30T14:25:35","guid":{"rendered":"https:\/\/www.yewen.us\/blog\/?p=3571"},"modified":"2019-05-30T22:25:35","modified_gmt":"2019-05-30T14:25:35","slug":"broken-cache-of-yarn","status":"publish","type":"post","link":"https:\/\/www.yewen.us\/blog\/2019\/05\/broken-cache-of-yarn\/","title":{"rendered":"\u8bb0\u4e00\u6b21\u8be1\u5f02\u7684\u88ab yarn \u5751\u7684\u8fc7\u7a0b"},"content":{"rendered":"<p>\u4e8b\u60c5\u7684\u8d77\u6e90\u662f @tdzl2003 \u8bf4\u4ed6\u7528 VSCode \u7684 remote \u6a21\u5f0f\u7528\u7684\u5f88\u5f00\u5fc3\uff0c\u653e\u5f03 Hyper-V \u56de\u5230 VirtualBox \u7684\u6000\u62b1\uff0c\u7b28\u72d7\u53bb\u770b\u4e86\u4e0b remote \u76f8\u5173\u529f\u80fd\u597d\u50cf\u8fd8\u5728 VSCode Insider \u91cc\uff0c\u53ef\u4ee5\u88c5\u6765\u8bd5\u8bd5\u770b\uff0c\u5f04\u597d\u540e\u770b\u4e86\u4e0b\u6587\u6863\u548c\u6559\u7a0b\uff0c\u77e5\u9053\u63d2\u4ef6\u5206\u88c5\u5728\u672c\u5730\u548c\u88c5\u5728\u8fdc\u7aef\uff0c\u4f46\u662f\u9879\u76ee\u91cc <code>eslint<\/code> \u63d2\u4ef6\u5c31\u4e00\u76f4\u5728\u62a5\u9519\uff0c\u8bf4\u627e\u4e0d\u5230\u6a21\u5757<\/p>\n<p>\u627e\u4e0d\u5230\u5c31\u53bb\u8865\u5427\uff0c\u5230\u8fdc\u7aef\u7684\u76ee\u5f55\u4e0b <code>yarn install<\/code> \u88c5\u597d\u4f9d\u8d56\uff0c\u56de\u5230\u672c\u5730\u4e00\u770b\uff0c\u8fd8\u662f\u62a5\u9519\uff0c\u600e\u4e48\u4f1a\u8fd9\u6837\uff1f\u5728\u8fdc\u7aef\u4e5f\u6267\u884c\u4e0b\u770b\u770b\uff1f<\/p>\n<pre class=\"brush: bash; gutter: false; title: ; notranslate\" title=\"\">\r\n$ .\/node_modules\/.bin\/eslint index.js\r\nError: Cannot find module 'jsx-ast-utils\/elementType'\r\n...\r\n<\/pre>\n<p>What the fuck?! \u4e00\u5b9a\u662f\u54ea\u91cc\u4e0d\u5bf9\uff0c\u628a <code>jsx-ast-utils<\/code> \u8fd9\u4e2a\u5305\u4e5f\u91cd\u88c5\u4e00\u4e0b\uff1f\u518d\u6765<\/p>\n<pre class=\"brush: bash; gutter: false; title: ; notranslate\" title=\"\">\r\n$ yarn add jsx-ast-utils\r\n$ .\/node_modules\/.bin\/eslint index.js\r\nError: Cannot find module 'jsx-ast-utils\/elementType'\r\n...\r\n<\/pre>\n<p>\u4f60\u7279\u4e48\u662f\u5728\u9017\u6211\uff1f\u53bb\u770b\u770b\u8fd9\u4e2a\u5305\u5230\u5e95\u600e\u4e48\u56de\u4e8b\uff0c\u91cc\u9762\u53ea\u6709 <code>lib<\/code> <code>src<\/code> \u4e24\u4e2a\u76ee\u5f55\uff0c\u5176\u4ed6\u90fd\u6ca1\u6709\uff0c\u770b\u8d77\u6765\u597d\u50cf\u662f\u4e0d\u592a\u5bf9<\/p>\n<p>\u786e\u8ba4\u4e86\u4e00\u4e0b\u73af\u5883\uff0cWindows 10 Pro 1903, WSL Ubuntu 18.04.2, node 12.3.1, yarn 1.16.0\uff0c\u90fd\u662f\u6700\u65b0\u7684\uff0c\u6362\u4e2a\u73af\u5883\u8bd5\u8bd5\u770b\uff1f\u5728\u81ea\u5df1\u53e6\u4e00\u53f0 MacBook Pro \u4e0a <code>yarn install<\/code> \u540e\u5c31\u662f\u6b63\u5e38\u7684\uff0chmmm\uff0c\u96be\u9053\u662f Windows \u76ee\u5f55\u6302\u8f7d\u5230 WSL \u4e0b\u540e\u6587\u4ef6\u6743\u9650\u5565\u7684\u9505\uff1f\u8bd5\u4e86\u4e0b\u5728 WSL \u91cc\u7528 WSL \u7684\u6587\u4ef6\u7cfb\u7edf\u91cd\u65b0\u6765\u8fc7\uff0c\u95ee\u9898\u4f9d\u65e7\u3002\u5728 Windows \u91cc\u628a WSL \u6620\u5c04\u6210\u7f51\u7edc\u76d8\uff0c\u7528 PowerShell \u8fdb\u5230 WSL \u6587\u4ef6\u7cfb\u7edf\u91cc <code>yarn install<\/code> \u5c31\u662f\u597d\u7684\uff0c\u55ef\uff1f\u597d\u4e86\uff1f\u56de\u5230 WSL \u4e0b\u6267\u884c PowerShell \u5b89\u88c5\u597d\u7684 <code>node_modules<\/code> \u4e5f\u6210\u529f<\/p>\n<p>\u96be\u9053\u662f WSL \u7684\u5947\u602a\u95ee\u9898\uff0c\u641c\u4e86\u4e0b\u597d\u50cf\u4e5f\u6ca1\u6709\u4efb\u4f55\u76f8\u5173\u4fe1\u606f\uff1f\u96be\u9053\u662f\u6700\u8fd1\u65b0\u5d29\u7684\u95ee\u9898\u6240\u4ee5\u5927\u5bb6\u90fd\u627e\u4e0d\u5230\uff0c\u6211\u5370\u8c61\u4e2d\u4e4b\u524d\u786e\u5b9e\u4e5f\u80fd\u8dd1\u6765\u7740\uff1f\u90a3\u5c31\u662f\u8fd9\u4e2a\u9505\u4e86\u3002\u7b49\u51e0\u4e4e\u8ba4\u5b9a\u5c31\u662f WSL \u6709\u5947\u602a\u7684\u95ee\u9898\u540e\uff0c\u665a\u4e0a\u56de\u5bb6\u540e\u62ff\u53e6\u4e00\u53f0\u540c\u6837\u73af\u5883\u7684\u673a\u5668\uff0c\u5728 WSL \u4e0b\u5c31\u6b63\u5e38\u7684\u88c5\u597d\u4e86<\/p>\n<p>\u8fd9\u8fd9\u8fd9\uff0c\u7b49\u4f1a\uff0c\u51b7\u9759\u4e00\u4e0b\uff0c\u4e00\u5b9a\u6709\u54ea\u91cc\u4e0d\u5bf9\uff0c\u8981\u4e0d\u7528\u4e0b\u91cd\u542f\u5927\u6cd5\uff1f\u628a\u6240\u6709\u76f8\u5173\u7684\u4e1c\u897f\u90fd\u5e72\u6389\u91cd\u6765\u4e00\u4e0b\uff1f\u5728\u6709\u95ee\u9898\u7684\u673a\u5668\u4e0a\uff0c\u628a git \u4ed3\u5e93\u6e05\u7a7a\u91cd\u6765\uff08\u867d\u7136\u4e4b\u524d\u5df2\u7ecf\u6362\u4e0d\u540c\u7684\u8def\u5f84\u505a\u8fc7\u4e86\uff09\uff0c\u628a nodejs \u548c yarn \u90fd\u5378\u8f7d\u91cd\u88c5\uff0c\u5bf9\u4e86\u662f\u4e0d\u662f\u8ddf yarn \u6e90\u8fd8\u6709\u5173\u7cfb\uff1f\u786e\u8ba4\u4e00\u4e0b<\/p>\n<pre class=\"brush: bash; gutter: false; title: ; notranslate\" title=\"\">\r\n$ yarn config get registry\r\nhttps:\/\/registry.yarnpkg.com\r\n<\/pre>\n<p>\u679c\u7136\u8fd9\u91cc\u4e0d\u4e00\u6837\uff0c\u5fd8\u4e86\u6539\u6210\u6dd8\u5b9d\u6e90\uff0c\u6539\u4e00\u4e2a\u518d\u6765\u4e00\u6b21\uff08\u5b98\u65b9\u6e90\u4e3a\u5565\u53ef\u80fd\u4f1a\u6709\u5751\u561b\uff0c\u96be\u9053\u662f\u6700\u8fd1\u649e\u5899\u649e\u7684\uff1f\u4e0d\u7ba1\u4e86\u5148\u6b7b\u9a6c\u5f53\u6d3b\u9a6c\u533b\u597d\u4e86\uff09<\/p>\n<pre class=\"brush: bash; gutter: false; title: ; notranslate\" title=\"\">\r\n$ yarn config set registry https:\/\/registry.npm.taobao.org\r\nyarn config v1.16.0\r\nsuccess Set &quot;registry&quot; to &quot;https:\/\/registry.npm.taobao.org&quot;.\r\nDone in 0.06s.\r\n<\/pre>\n<p>\u8fd9\u4e0b\u5e94\u8be5\u6ca1\u95ee\u9898\u4e86\uff0c\u8d70\u4f60\uff0c\u7b49 <code>yarn install<\/code> \u8dd1\u5b8c\uff0c\u5148\u68c0\u67e5\u4e0b <code>node_modules\/jsx-ast\/utils\/<\/code> \u8def\u5f84\u4e0b\u6587\u4ef6\u5bf9\u4e0d\u5bf9\uff0c\u55ef\uff1f\u8fd8\u662f\u53ea\u6709 <code>lib<\/code> <code>src<\/code> \u8fd9\u4e24\u4e2a\u6587\u4ef6\u5939\uff1f\u8fd9\u5230\u5e95\u662f\u4e3a\u4ec0\u4e48\u554a\uff0cyarn \u4f60\u8fd9\u4e2a\u5751\u8d27\uff0c\u8981\u4e0d\u6362 npm \u8bd5\u8bd5\u770b\uff1f<\/p>\n<p><code>npm install<\/code> \u8dd1\u4e00\u4e0b\uff0c\u63d0\u793a\u6709\u6587\u4ef6\u6743\u9650\u4e0d\u5bf9\uff0c\u770b\u4e86\u4e0b\uff0c\u54e6\u662f\u4e4b\u524d\u6709 <code>sudo npm install -g<\/code> \u88c5\u8fc7\u4e1c\u897f\uff0c\u628a <code>~\/.npm<\/code> \u76ee\u5f55\u4e0b\u76f8\u5173\u5185\u5bb9\u6e05\u6389\u5c31\u597d\u4e86\u3002\u7528 npm \u88c5\u5b8c\u4e00\u770b\uff0c\u597d\u4e86\u3002\u3002\u3002\u5443\uff0c\u679c\u7136 yarn \u4f60\u4e2a\u5751\u8d27\u5230\u5e95\u54ea\u91cc\u4e0d\u5bf9\u554a\uff01\uff1f<\/p>\n<p>\u7f13\u5b58\uff1f\u53bb\u5427 <code>~\/.yarn<\/code> \u4e0b\u7684\u5185\u5bb9\u90fd\u6e05\u6389\uff0c<code>\/tmp<\/code> \u4e0b\u6709\u4e00\u5806 <code>yarn-<\/code> \u5f00\u5934\u7684\u4e0d\u77e5\u9053\u662f\u5565\u5e94\u8be5\u4e5f\u90fd\u53ef\u4ee5\u5e72\u6389\uff0c\u518d\u6765\uff0c\u8fd8\u6302\uff1f\u53bb\u641c <code>yarn install package missing files<\/code>\uff0c\u7ec8\u4e8e\u770b\u5230\u4e86\u4e00\u4e2a\u5f88\u76f8\u4f3c\u7684\u60c5\u51b5\uff0c\u4e0d\u8fc7\u4ed6\u8fd9\u4e2a\u6700\u540e\u4e5f\u662f\u6e05\u4e86 yarn \u7684 cache \u5c31\u597d\u4e86\u3002\u770b\u4e86\u4e0b\u9664\u4e86 <code>~\/.yarn<\/code> \u8fd8\u6709\u4eba\u8bf4 Cache \u76ee\u5f55\u662f <code>~\/.yarn-cache<\/code> \u76ee\u5f55\uff0c\u4f46\u662f\u6211\u538b\u6839\u90fd\u6ca1\u8fd9\u4e2a\u76ee\u5f55\u554a\u3002\u987a\u7740\u8fd9\u6761\u7ebf\u7d22\u7ee7\u7eed\u641c\uff0c\u627e\u5230 <code>yarn cache clean<\/code> \u8fd9\u4e2a\u547d\u4ee4\uff0c\u6267\u884c\u540e\u518d\u88c5\u5c31\u597d\u4e86<\/p>\n<p>\u90a3\u770b\u6765\u5c31\u662f\u4e4b\u524d\u7684\u7f13\u5b58\u6709\u95ee\u9898\uff0c\u800c\u6211\u5f04\u8fd9\u4e48\u591a\u5404\u79cd\u91cd\u88c5\u4e5f\u5e76\u6ca1\u6709\u6e05\u6389 cache\uff0c\u6216\u8005\u89e6\u53d1\u91cd\u65b0\u4ece\u8fdc\u7aef\u62c9\u5305\u3002\u90a3\u4e48 yarn \u7684 cache \u5230\u5e95\u5728\u54ea\u91cc\uff1f\u5230\u7528\u6237\u6839\u76ee\u5f55\u4e0b\u67e5\u770b\u6240\u6709\u6587\u4ef6\uff0c\u53d1\u73b0\u6709\u4e00\u4e2a\u76ee\u5f55\u53eb <code>.cache<\/code>\uff0c\u770b\u7740\u633a\u53ef\u7591\uff0c\u8fdb\u53bb\u770b\u770b\u679c\u7136\u91cc\u9762\u6709 <code>pip<\/code> \u548c <code>yarn<\/code> \u7b49\u76ee\u5f55\uff0c\u770b\u4e86\u4e0b\u91cc\u9762\u6587\u4ef6\u65f6\u95f4\uff0c\u5c31\u662f\u8fd9\u4e86\uff0c\u5e94\u8be5\u5c31\u662f\u4e4b\u524d\u67d0\u6b21\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u88ab\u5f3a\u5236\u9000\u51fa\uff0c\u5bfc\u81f4\u90a3\u4e2a\u70b9\u5728\u88c5\u7684\u4e00\u4e2a\u6216\u51e0\u4e2a\u5305\u662f\u4e0d\u5bf9\u7684\uff0c\u4f46\u662f\u76ee\u5f55\u8fd8\u5728 yarn \u5c31\u4e00\u76f4\u50bb\u4e4e\u4e4e\u7684\u7528\u672c\u5730\u7684<\/p>\n<p>\u7ed3\u8bba\uff1ayarn \u7684 cache \u673a\u5236\u5bf9\u5305\u7684\u5b8c\u6574\u6027\u4fdd\u8bc1\u4e0d\u591f\uff0c\u5982\u679c\u4e4b\u524d\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u6709\u5f02\u5e38\u9000\u51fa\uff0c\u8d76\u4e0a\u5f02\u5e38\u9000\u51fa\u8fc7\u7a0b\u4e2d\u7684\u5305\u5c31\u6709\u53ef\u80fd\u635f\u574f\uff0c\u540e\u9762\u5982\u679c\u4e0d\u624b\u52a8\u6e05 cache\uff0c\u5c31\u4f1a\u4e00\u76f4\u6302<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e8b\u60c5\u7684\u8d77\u6e90\u662f @tdzl2003 \u8bf4\u4ed6\u7528 VSCode \u7684 remote \u6a21\u5f0f\u7528\u7684\u5f88\u5f00\u5fc3\uff0c\u653e\u5f03 Hyper-V [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[7],"tags":[696,697,662,695],"class_list":["post-3571","post","type-post","status-publish","format-standard","hentry","category-tech-notes","tag-cache","tag-npm","tag-wsl","tag-yarn"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4aR5e-VB","_links":{"self":[{"href":"https:\/\/www.yewen.us\/blog\/wp-json\/wp\/v2\/posts\/3571","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yewen.us\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yewen.us\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yewen.us\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yewen.us\/blog\/wp-json\/wp\/v2\/comments?post=3571"}],"version-history":[{"count":6,"href":"https:\/\/www.yewen.us\/blog\/wp-json\/wp\/v2\/posts\/3571\/revisions"}],"predecessor-version":[{"id":3577,"href":"https:\/\/www.yewen.us\/blog\/wp-json\/wp\/v2\/posts\/3571\/revisions\/3577"}],"wp:attachment":[{"href":"https:\/\/www.yewen.us\/blog\/wp-json\/wp\/v2\/media?parent=3571"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yewen.us\/blog\/wp-json\/wp\/v2\/categories?post=3571"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yewen.us\/blog\/wp-json\/wp\/v2\/tags?post=3571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}