{"id":1228,"date":"2020-05-28T16:00:15","date_gmt":"2020-05-28T08:00:15","guid":{"rendered":"https:\/\/freesilo.com\/?p=1228"},"modified":"2020-06-26T16:01:25","modified_gmt":"2020-06-26T08:01:25","slug":"npm%e8%ae%be%e7%bd%ae%e4%bb%a3%e7%90%86-proxy%e3%80%81%e9%85%8d%e7%bd%ae%e5%9b%bd%e5%86%85%e6%ba%90","status":"publish","type":"post","link":"https:\/\/freesilo.com\/?p=1228","title":{"rendered":"npm\u8bbe\u7f6e\u4ee3\u7406 proxy\u3001\u914d\u7f6e\u56fd\u5185\u6e90"},"content":{"rendered":"<p>npm\u5168\u79f0\u4e3aNode Packaged Modules\u3002\u5b83\u662f\u4e00\u4e2a\u7528\u4e8e\u7ba1\u7406\u57fa\u4e8enode.js\u7f16\u5199\u7684package\u7684\u547d\u4ee4\u884c\u5de5\u5177\u3002\u5176\u672c\u8eab\u5c31\u662f\u57fa\u4e8enode.js\u5199\u7684,\u8fd9\u6709\u70b9\u50cfgem\u4e0eruby\u7684\u5173\u7cfb\u3002<\/p>\n<p>\u5728\u6211\u4eec\u7684\u9879\u76ee\u4e2d\uff0c\u9700\u8981\u4f7f\u7528\u4e00\u4e9b\u57fa\u4e8enode.js\u7684javascript\u5e93\u6587\u4ef6\uff0c\u5c31\u9700\u8981npm\u5bf9\u8fd9\u4e9b\u4f9d\u8d56\u5e93\u8fdb\u884c\u65b9\u4fbf\u7684\u7ba1\u7406\u3002\u7531\u4e8e\u6211\u4eec\u7684\u5f00\u53d1\u73af\u5883\u7531\u4e8e\u5b89\u5168\u56e0\u7d20\u5728\u8bbf\u95ee\u4e00\u4e9b\u7f51\u7ad9\u65f6\u9700\u8981\u4f7f\u7528\u4ee3\u7406\uff0c\u5176\u4e2d\u5c31\u5305\u62ecnpm\u7684repositories\u7f51\u7ad9\uff0c\u6240\u4ee5\u5c31\u9700\u8981\u4fee\u6539npm\u7684\u914d\u7f6e\u6765\u52a0\u5165\u4ee3\u7406\u3002<\/p>\n<p>\u4e0b\u9762\u7b80\u8981\u4ecb\u7ecd\u4e0bnpm\u7684\u914d\u7f6e\u4ee5\u53ca\u5982\u4f55\u8bbe\u7f6e\u4ee3\u7406\u3002<\/p>\n<h2>npm\u83b7\u53d6\u914d\u7f6e\u67096\u79cd\u65b9\u5f0f\uff0c\u4f18\u5148\u7ea7\u7531\u9ad8\u5230\u5e95\u3002<\/h2>\n<ol>\n<li>\u547d\u4ee4\u884c\u53c2\u6570\u3002\u00a0<code>--proxy http:\/\/server:port<\/code>\u5373\u5c06proxy\u7684\u503c\u8bbe\u4e3a<code>http:\/\/server:port<\/code>\u3002<\/li>\n<li>\u73af\u5883\u53d8\u91cf\u3002 \u4ee5<code>npm_config_<\/code>\u4e3a\u524d\u7f00\u7684\u73af\u5883\u53d8\u91cf\u5c06\u4f1a\u88ab\u8ba4\u4e3a\u662fnpm\u7684\u914d\u7f6e\u5c5e\u6027\u3002\u5982\u8bbe\u7f6eproxy\u53ef\u4ee5\u52a0\u5165\u8fd9\u6837\u7684\u73af\u5883\u53d8\u91cf<code>npm_config_proxy=http:\/\/server:port<\/code>\u3002<\/li>\n<li>\u7528\u6237\u914d\u7f6e\u6587\u4ef6\u3002\u53ef\u4ee5\u901a\u8fc7<code>npm config get userconfig<\/code>\u67e5\u770b\u6587\u4ef6\u8def\u5f84\u3002\u5982\u679c\u662fmac\u7cfb\u7edf\u7684\u8bdd\u9ed8\u8ba4\u8def\u5f84\u5c31\u662f<code>$HOME\/.npmrc<\/code>\u3002<\/li>\n<li>\u5168\u5c40\u914d\u7f6e\u6587\u4ef6\u3002\u53ef\u4ee5\u901a\u8fc7<code>npm config get globalconfig<\/code>\u67e5\u770b\u6587\u4ef6\u8def\u5f84\u3002mac\u7cfb\u7edf\u7684\u9ed8\u8ba4\u8def\u5f84\u662f<code>\/usr\/local\/etc\/npmrc<\/code>\u3002<\/li>\n<li>\u5185\u7f6e\u914d\u7f6e\u6587\u4ef6\u3002\u5b89\u88c5npm\u7684\u76ee\u5f55\u4e0b\u7684npmrc\u6587\u4ef6\u3002<\/li>\n<li>\u9ed8\u8ba4\u914d\u7f6e\u3002 npm\u672c\u8eab\u6709\u9ed8\u8ba4\u914d\u7f6e\u53c2\u6570\uff0c\u5982\u679c\u4ee5\u4e0a5\u6761\u90fd\u6ca1\u8bbe\u7f6e\uff0c\u5219npm\u4f1a\u4f7f\u7528\u9ed8\u8ba4\u914d\u7f6e\u53c2\u6570\u3002<\/li>\n<\/ol>\n<h2>\u9488\u5bf9npm\u914d\u7f6e\u7684\u547d\u4ee4\u884c\u64cd\u4f5c<\/h2>\n<figure class=\"code\"><figcaption><\/figcaption><div class=\"highlight\">\n<table>\n<tbody>\n<tr>\n<td class=\"gutter\">\n<pre class=\"line-numbers\"><span class=\"line-number\">1<\/span>\r\n<span class=\"line-number\">2<\/span>\r\n<span class=\"line-number\">3<\/span>\r\n<span class=\"line-number\">4<\/span>\r\n<span class=\"line-number\">5<\/span>\r\n<span class=\"line-number\">6<\/span>\r\n<span class=\"line-number\">7<\/span>\r\n<\/pre>\n<\/td>\n<td class=\"code\">\n<pre><code class=\"bash hljs\"><span class=\"line\">   npm config <span class=\"nb\"><span class=\"hljs-built_in\">set<\/span><\/span> &lt;key&gt; &lt;value&gt; <span class=\"o\">[<\/span>--global<span class=\"o\">]<\/span>\r\n<\/span><span class=\"line\">   npm config get &lt;key&gt;\r\n<\/span><span class=\"line\">   npm config delete &lt;key&gt;\r\n<\/span><span class=\"line\">   npm config list\r\n<\/span><span class=\"line\">   npm config edit\r\n<\/span><span class=\"line\">   npm get &lt;key&gt;\r\n<\/span><span class=\"line\">   npm <span class=\"nb\"><span class=\"hljs-built_in\">set<\/span><\/span> &lt;key&gt; &lt;value&gt; <span class=\"o\">[<\/span>--global<span class=\"o\">]<\/span>\r\n<\/span><\/code><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/figure>\n<p>\u5728\u8bbe\u7f6e\u914d\u7f6e\u5c5e\u6027\u65f6\u5c5e\u6027\u503c\u9ed8\u8ba4\u662f\u88ab\u5b58\u50a8\u4e8e\u7528\u6237\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u5982\u679c\u52a0\u4e0a<code>--global<\/code>\uff0c\u5219\u88ab\u5b58\u50a8\u5728\u5168\u5c40\u914d\u7f6e\u6587\u4ef6\u4e2d\u3002<\/p>\n<p>\u5982\u679c\u8981\u67e5\u770bnpm\u7684\u6240\u6709\u914d\u7f6e\u5c5e\u6027\uff08\u5305\u62ec\u9ed8\u8ba4\u914d\u7f6e\uff09\uff0c\u53ef\u4ee5\u4f7f\u7528<code>npm config ls -l<\/code>\u3002<\/p>\n<p>\u5982\u679c\u8981\u67e5\u770bnpm\u7684\u5404\u79cd\u914d\u7f6e\u7684\u542b\u4e49\uff0c\u53ef\u4ee5\u4f7f\u7528<code>npm help config<\/code>\u3002<\/p>\n<h1 id=\"\u8bbe\u7f6e\u4ee3\u7406\">\u8bbe\u7f6e\u4ee3\u7406<\/h1>\n<p>1.\u9996\u5148\u67e5\u770b\u4e0b\u76ee\u524d\u914d\u7f6e:npm config list \u67e5\u770b\u662f\u5426\u5df2\u7ecf\u914d\u7f6e\u4e86<\/p>\n<p>2.\u8bbe\u7f6e\u7f51\u7edc\u4ee3\u7406\u7684\u547d\u4ee4\u5982\u4e0b\uff1anpm config set proxy=&#8221;http:\/\/192.168.2.1:8080&#8243;<\/p>\n<p>3.\u56fd\u5916\u6e90\u901f\u5ea6\u4e0d\u7a33\u5b9a\uff0c\u53ef\u8bbe\u7f6e\u56fd\u5185\u6dd8\u5b9d\u6e90\u3002\u67e5\u770b\u73b0\u6709\u6e90\u00a0\u00a0npm config get registry<\/p>\n<p>4.\u8bbe\u7f6e\u6dd8\u5b9d\u6e90\uff1anpm config set registry https:\/\/registry.npm.taobao.org<\/p>\n<p>5.\u518d\u6b21\u67e5\u770b\u5373\u53ef\u786e\u8ba4\u6e90\u5df2\u4fee\u6539\u3002\u7528\u65b0\u6e90\u66f4\u65b0\u4e00\u6ce2package\uff1anpm update<\/p>\n<h2 id=\"http-\u4ee3\u7406\">http \u4ee3\u7406<\/h2>\n<p>npm \u539f\u751f\u652f\u6301 http \u4ee3\u7406\uff0c\u76f4\u63a5\u8bbe\u7f6e\u5373\u53ef<\/p>\n<figure class=\"highlight bash\">\n<table>\n<tbody>\n<tr>\n<td class=\"gutter\">\n<pre><span class=\"line\">1<\/span>\r\n<span class=\"line\">2<\/span>\r\n<span class=\"line\">3<\/span>\r\n<span class=\"line\">4<\/span>\r\n<span class=\"line\">5<\/span>\r\n<span class=\"line\">6<\/span>\r\n<span class=\"line\">7<\/span><\/pre>\n<\/td>\n<td class=\"code\">\n<pre><span class=\"line\"><span class=\"comment\"># \u5047\u8bbe\u672c\u5730\u4ee3\u7406\u7aef\u53e3\u4e3a8080<\/span><\/span>\r\n<span class=\"line\">npm config <span class=\"built_in\">set<\/span> proxy <span class=\"string\">\"http:\/\/localhost:8080\"<\/span><\/span>\r\n<span class=\"line\">npm config <span class=\"built_in\">set<\/span> https-proxy <span class=\"string\">\"http:\/\/localhost:8080\"<\/span><\/span>\r\n\r\n<span class=\"line\"><span class=\"comment\"># \u6709\u7528\u6237\u5bc6\u7801\u7684\u4ee3\u7406<\/span><\/span>\r\n<span class=\"line\">npm config <span class=\"built_in\">set<\/span> proxy <span class=\"string\">\"http:\/\/username:password@localhost:8080\"<\/span><\/span>\r\n<span class=\"line\">npm confit <span class=\"built_in\">set<\/span> https-proxy <span class=\"string\">\"http:\/\/username:password@localhost:8080\"<\/span><\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<h2 id=\"socks5-\u4ee3\u7406\">socks5 \u4ee3\u7406<\/h2>\n<p>npm \u4e0d\u652f\u6301 socks \u4ee3\u7406\uff0c\u4f46\u662f\u6211\u4eec\u53ef\u4ee5\u7528\u4e00\u4e2a\u5de5\u5177\u5c06 http \u4ee3\u7406\u8f6c\u6210 socks \u4ee3\u7406\uff0c\u7136\u540e\u5c06 npm \u4ee3\u7406\u5730\u5740\u8bbe\u7f6e\u5230\u8fd9\u4e2a\u5de5\u5177\u7684\u5730\u5740\u3002<\/p>\n<figure class=\"highlight bash\">\n<table>\n<tbody>\n<tr>\n<td class=\"gutter\">\n<pre><span class=\"line\">1<\/span>\r\n<span class=\"line\">2<\/span>\r\n<span class=\"line\">3<\/span>\r\n<span class=\"line\">4<\/span>\r\n<span class=\"line\">5<\/span>\r\n<span class=\"line\">6<\/span>\r\n<span class=\"line\">7<\/span>\r\n<span class=\"line\">8<\/span><\/pre>\n<\/td>\n<td class=\"code\">\n<pre><span class=\"line\"><span class=\"comment\"># \u5047\u8bbe\u672c\u5730socks5\u4ee3\u7406\u7aef\u53e3\u4e3a8081<\/span><\/span>\r\n<span class=\"line\"><span class=\"comment\"># \u9996\u5148\u5b89\u88c5\u8f6c\u6362\u5de5\u5177<\/span><\/span>\r\n<span class=\"line\">npm install -g http-proxy-to-socks<\/span>\r\n<span class=\"line\"><span class=\"comment\"># \u7136\u540e\u4f7f\u7528\u8fd9\u4e2a\u5de5\u5177\u76d1\u542c8080\u7aef\u53e3,\u652f\u6301http\u4ee3\u7406\uff0c\u7136\u540e\u6240\u67098080\u7684http\u4ee3\u7406\u6570\u636e\u90fd\u5c06\u8f6c\u6362\u6210socks\u7684\u4ee3\u7406\u6570\u636e\u53d1\u9001\u52308081\u4e0a<\/span><\/span>\r\n<span class=\"line\">hpts -s localhost:8081 -p 8080<\/span>\r\n<span class=\"line\"><span class=\"comment\"># \u6700\u540e\u8bbe\u7f6enpm\u4ee3\u7406\u4e3a8080<\/span><\/span>\r\n<span class=\"line\">npm config <span class=\"built_in\">set<\/span> proxy <span class=\"string\">\"http:\/\/localhost:8080\"<\/span><\/span>\r\n<span class=\"line\">npm config <span class=\"built_in\">set<\/span> https-proxy <span class=\"string\">\"http:\/\/localhost:8080\"<\/span><\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p>\u76f8\u5f53\u4e8e\u53c8\u52a0\u4e86\u4e00\u4e2a\u4e2d\u95f4\u5c42\uff0c\u5c06 http \u8f6c\u6210 socks\u3002<\/p>\n<h2 id=\"\u5220\u9664\u4ee3\u7406\">\u5220\u9664\u4ee3\u7406<\/h2>\n<figure class=\"highlight bash\">\n<table>\n<tbody>\n<tr>\n<td class=\"gutter\">\n<pre><span class=\"line\">1<\/span>\r\n<span class=\"line\">2<\/span><\/pre>\n<\/td>\n<td class=\"code\">\n<pre><span class=\"line\">npm config delete proxy<\/span>\r\n<span class=\"line\">npm config delete https-proxy<\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<div class=\"highlight highlight-source-shell\">\n<pre><\/pre>\n<h2 id=\"\u4fee\u6539\u6e90\">\u4fee\u6539\u6e90<\/h2>\n<p>\u5982\u679c\u4ee3\u7406\u4e0d\u652f\u6301https\u7684\u8bdd\u9700\u8981\u4fee\u6539npm\u5b58\u653epackage\u7684\u7f51\u7ad9\u5730\u5740\u3002<\/p>\n<p>$\u00a0npm\u00a0config\u00a0set\u00a0registry\u00a0&#8220;http:\/\/registry.npmjs.org\/&#8221;<\/p>\n<pre>$ npm config <span class=\"pl-c1\">set<\/span> registry <span class=\"pl-s\"><span class=\"pl-pds\">'<\/span>https:\/\/registry.npm.taobao.org<span class=\"pl-pds\">'<\/span><\/span>\r\n<span class=\"pl-k\">$ export<\/span> ELECTRON_MIRROR=<span class=\"pl-s\"><span class=\"pl-pds\">'<\/span>https:\/\/npm.taobao.org\/mirrors\/electron\/<span class=\"pl-pds\">'<\/span><\/span>\r\n<span class=\"pl-k\">$ export<\/span> SASS_BINARY_SITE=<span class=\"pl-s\"><span class=\"pl-pds\">'<\/span>https:\/\/npm.taobao.org\/mirrors\/node-sass<span class=\"pl-pds\">'<\/span><\/span><\/pre>\n<\/div>\n<blockquote><p>Error: Electron failed to install correctly, please delete node_modules\/electron and try installing again<\/p><\/blockquote>\n<p><code>Electron<\/code>\u00a0\u4e0b\u8f7d\u5b89\u88c5\u5931\u8d25\u7684\u95ee\u9898\uff0c\u89e3\u51b3\u65b9\u5f0f\u8bf7\u53c2\u8003\u00a0<a href=\"https:\/\/github.com\/electron\/electron\/issues\/8466#issuecomment-571425574\">https:\/\/github.com\/electron\/electron\/issues\/8466#issuecomment-571425574<\/a><\/p>\n<div id=\"gtx-trans\" style=\"position: absolute; left: -33px; top: 176px;\">\n<div class=\"gtx-trans-icon\"><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>npm\u5168\u79f0\u4e3aNode Packaged Modules\u3002\u5b83\u662f\u4e00\u4e2a\u7528\u4e8e\u7ba1\u7406\u57fa\u4e8eno&#8230;<br \/><a class=\"read-more-button\" href=\"https:\/\/freesilo.com\/?p=1228\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-1228","post","type-post","status-publish","format-standard","hentry","category-web"],"_links":{"self":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/1228","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1228"}],"version-history":[{"count":3,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/1228\/revisions"}],"predecessor-version":[{"id":1250,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/1228\/revisions\/1250"}],"wp:attachment":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}