{"id":253,"date":"2025-06-30T18:04:07","date_gmt":"2025-06-30T10:04:07","guid":{"rendered":"https:\/\/www.idcyz.com\/blog\/?p=253"},"modified":"2025-06-30T18:04:07","modified_gmt":"2025-06-30T10:04:07","slug":"%e4%b8%ba%e4%bb%80%e4%b9%88-npm-install-%e4%b8%80%e7%9b%b4%e5%8d%a1%e4%bd%8f%ef%bc%9f%e6%9c%80%e6%96%b0%e5%8e%9f%e5%9b%a0%e4%b8%8e%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.idcyz.com\/blog\/253.html","title":{"rendered":"\u4e3a\u4ec0\u4e48 npm install \u4e00\u76f4\u5361\u4f4f\uff1f\u6700\u65b0\u539f\u56e0\u4e0e\u89e3\u51b3\u529e\u6cd5"},"content":{"rendered":"<p><h2>npm install \u4e00\u76f4\u5361\u4f4f\u7684\u539f\u56e0\u548c\u89e3\u51b3\u65b9\u6848<\/h2>\n<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.idcyz.com\/blog\/wp-content\/uploads\/2025\/06\/JUya94.jpg\" alt=\"\u4e3a\u4ec0\u4e48 npm install \u4e00\u76f4\u5361\u4f4f\uff1f\u6700\u65b0\u539f\u56e0\u4e0e\u89e3\u51b3\u529e\u6cd5\" title=\"\u4e3a\u4ec0\u4e48 npm install \u4e00\u76f4\u5361\u4f4f\uff1f\u6700\u65b0\u539f\u56e0\u4e0e\u89e3\u51b3\u529e\u6cd5\"><\/p>\n<p><p>\u5728\u4f7f\u7528 Node.js \u5f00\u53d1\u9879\u76ee\u65f6\uff0c<strong>npm install<\/strong> \u547d\u4ee4\u662f\u975e\u5e38\u5e38\u89c1\u7684\uff0c\u7528\u4e8e\u5b89\u88c5\u4f9d\u8d56\u5305\u3002\u7136\u800c\uff0c\u6709\u65f6\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u51fa\u73b0\u5361\u4f4f\u7684\u60c5\u51b5\uff0c\u5bfc\u81f4\u65e0\u6cd5\u6b63\u5e38\u5b89\u88c5\u4f9d\u8d56\u3002\u672c\u6587\u5c06\u6df1\u5165\u63a2\u8ba8\u9020\u6210 <strong>npm install<\/strong> \u5361\u4f4f\u7684\u5404\u79cd\u539f\u56e0\uff0c\u5e76\u63d0\u4f9b\u8be6\u7ec6\u7684\u89e3\u51b3\u6b65\u9aa4\u548c\u5b9e\u7528\u6280\u5de7\u3002<\/p>\n<\/p>\n<p><h3>\u5e38\u89c1\u539f\u56e0<\/h3>\n<\/p>\n<ul>\n<li><strong>\u7f51\u7edc\u95ee\u9898\uff1a<\/strong>\u6700\u5e38\u89c1\u7684\u539f\u56e0\u662f\u7f51\u7edc\u8fde\u63a5\u4e0d\u7a33\u5b9a\uff0c\u5bfc\u81f4\u65e0\u6cd5\u8bbf\u95ee npm \u6ce8\u518c\u5e93\u3002<\/li>\n<li><strong>npm \u7f13\u5b58\u95ee\u9898\uff1a<\/strong>\u6709\u65f6 npm \u7684\u7f13\u5b58\u635f\u574f\u4e5f\u4f1a\u5bfc\u81f4\u5b89\u88c5\u5361\u4f4f\u3002<\/li>\n<li><strong>\u4ee3\u7406\u8bbe\u7f6e\u95ee\u9898\uff1a<\/strong>\u5982\u679c\u5728\u4f7f\u7528\u4ee3\u7406\uff0c\u6709\u65f6\u4ee3\u7406\u914d\u7f6e\u4e0d\u5f53\u4f1a\u5bfc\u81f4\u8bf7\u6c42\u5931\u8d25\u3002<\/li>\n<li><strong>node_modules \u76ee\u5f55\u635f\u574f\uff1a<\/strong>\u5b58\u5728\u95ee\u9898\u7684 node_modules \u76ee\u5f55\u53ef\u80fd\u5bfc\u81f4\u5b89\u88c5\u5931\u8d25\u3002<\/li>\n<li><strong>package.json \u6587\u4ef6\u635f\u574f\uff1a<\/strong>\u5982\u679c package.json \u6587\u4ef6\u683c\u5f0f\u4e0d\u6b63\u786e\uff0c\u4e5f\u53ef\u80fd\u5bfc\u81f4\u5b89\u88c5\u5361\u4f4f\u3002<\/li>\n<\/ul>\n<p><h3>\u64cd\u4f5c\u6b65\u9aa4<\/h3>\n<\/p>\n<p><h4>\u6b65\u9aa4\u4e00\uff1a\u68c0\u67e5\u7f51\u7edc\u8fde\u63a5<\/h4>\n<\/p>\n<p><p>\u9996\u5148\u68c0\u67e5\u4f60\u7684\u7f51\u7edc\u8fde\u63a5\u662f\u5426\u6b63\u5e38\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u6d4b\u8bd5\u7f51\u7edc\u662f\u5426\u901a\u7545\uff1a<\/p>\n<\/p>\n<p><pre><code>ping registry.npmjs.org<\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c ping \u547d\u4ee4\u8fd4\u56de\u8d85\u65f6\u4fe1\u606f\uff0c\u8bf4\u660e\u7f51\u7edc\u6709\u95ee\u9898\u3002\u6b64\u65f6\u53ef\u4ee5\u8003\u8651\u4ee5\u4e0b\u51e0\u79cd\u5904\u7406\u65b9\u6848\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u5207\u6362\u7f51\u7edc\uff1a<\/strong>\u5c1d\u8bd5\u8fde\u63a5\u53e6\u4e00\u6761\u7f51\u7edc\u3002<\/li>\n<li><strong>\u4f7f\u7528 VPN\uff1a<\/strong>\u6709\u65f6\u4e00\u4e9b\u5730\u533a\u53ef\u80fd\u65e0\u6cd5\u8bbf\u95ee npm \u6ce8\u518c\u5e93\uff0c\u4f7f\u7528 VPN \u53ef\u80fd\u4f1a\u6709\u6240\u5e2e\u52a9\u3002<\/li>\n<\/ul>\n<p><h4>\u6b65\u9aa4\u4e8c\uff1a\u4f7f\u7528 <strong>npm config set<\/strong> \u4fee\u6539 npm \u6e90<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u7f51\u7edc\u6761\u4ef6\u4e0d\u662f\u95ee\u9898\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u66f4\u6362 npm \u6e90\uff0c\u4f8b\u5982\u4f7f\u7528 <strong>\u6dd8\u5b9d\u955c\u50cf<\/strong>\uff0c\u56e0\u4e3a\u5728\u56fd\u5185\u8bbf\u95ee npm \u5b98\u65b9\u6e90\u53ef\u80fd\u4f1a\u6bd4\u8f83\u6162\uff1a<\/p>\n<\/p>\n<p><pre><code>npm config set registry https:\/\/registry.npm.taobao.org<\/code><\/pre>\n<\/p>\n<p><p>\u5207\u6362\u540e\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u518d\u6b21\u8fd0\u884c <strong>npm install<\/strong> \u547d\u4ee4\uff0c\u770b\u95ee\u9898\u662f\u5426\u89e3\u51b3\u3002<\/p>\n<\/p>\n<p><h4>\u6b65\u9aa4\u4e09\uff1a\u6e05\u7406 npm \u7f13\u5b58<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u95ee\u9898\u4f9d\u65e7\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u6e05\u9664 npm \u7f13\u5b58\u3002\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code>npm cache clean --force<\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u518d\u6b21\u8fd0\u884c <strong>npm install<\/strong> \u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<\/p>\n<p><h4>\u6b65\u9aa4\u56db\uff1a\u5220\u9664 node_modules \u548c package-lock.json \u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u6709\u65f6<em>node_modules<\/em> \u76ee\u5f55\u6216 <em>package-lock.json<\/em> \u6587\u4ef6\u4e2d\u7684\u67d0\u4e9b\u4f9d\u8d56\u9879\u53ef\u80fd\u906d\u5230\u7834\u574f\u3002\u53ef\u4ee5\u5220\u9664\u8fd9\u4e9b\u6587\u4ef6\u5e76\u91cd\u65b0\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code>rm -rf node_modules<\/code><\/pre>\n<\/p>\n<p><pre><code>rm package-lock.json<\/code><\/pre>\n<\/p>\n<p><pre><code>npm install<\/code><\/pre>\n<\/p>\n<p><p>\u6b64\u6b65\u9aa4\u80fd\u6709\u6548\u89e3\u51b3\u8bb8\u591a\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u51fa\u73b0\u7684\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><h4>\u6b65\u9aa4\u4e94\uff1a\u68c0\u67e5 package.json \u683c\u5f0f<\/h4>\n<\/p>\n<p><p>\u786e\u4fdd\u4f60\u7684 <strong>package.json<\/strong> \u6587\u4ef6\u683c\u5f0f\u6b63\u786e\uff0c\u53ef\u4ee5\u4f7f\u7528 JSON \u6821\u9a8c\u5de5\u5177\u8fdb\u884c\u68c0\u67e5\u3002\u786e\u4fdd\u6ca1\u6709\u591a\u4f59\u7684\u9017\u53f7\u6216\u8005\u62fc\u5199\u9519\u8bef\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u4e2a\u793a\u4f8b\u7684 <strong>package.json<\/strong> \u6587\u4ef6\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code>{<\/p>\r\n<p>  \"name\": \"my-app\",<\/p>\r\n<p>  \"version\": \"1.0.0\",<\/p>\r\n<p>  \"description\": \"My application description\",<\/p>\r\n<p>  \"main\": \"index.js\",<\/p>\r\n<p>  \"scripts\": {<\/p>\r\n<p>    \"start\": \"node index.js\"<\/p>\r\n<p>  },<\/p>\r\n<p>  \"dependencies\": {<\/p>\r\n<p>    \"express\": \"^4.17.1\"<\/p>\r\n<p>  }<\/p>\r\n<p>}<\/code><\/pre>\n<\/p>\n<p><h4>\u6b65\u9aa4\u516d\uff1a\u8c03\u8bd5\u5b89\u88c5\u8fc7\u7a0b<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u901a\u8fc7\u589e\u52a0\u8c03\u8bd5\u4fe1\u606f\u6765\u83b7\u5f97\u66f4\u591a\u5173\u4e8e\u5b89\u88c5\u8fc7\u7a0b\u7684\u4fe1\u606f\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code>npm install --verbose<\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6837\u53ef\u4ee5\u8f93\u51fa\u66f4\u8be6\u7ec6\u7684\u65e5\u5fd7\uff0c\u6709\u52a9\u4e8e\u8bc6\u522b\u51fa\u95ee\u9898\u6240\u5728\u3002<\/p>\n<\/p>\n<p><h4>\u6b65\u9aa4\u4e03\uff1a\u4f7f\u7528 <strong>npm doctor<\/strong> \u68c0\u67e5 npm \u73af\u5883<\/h4>\n<\/p>\n<p><p>\u901a\u8fc7 <strong>npm doctor<\/strong> \u547d\u4ee4\u53ef\u4ee5\u68c0\u67e5 npm \u7684\u73af\u5883\u8bbe\u7f6e\u3002\u8fd9\u53ef\u4ee5\u5e2e\u52a9\u4f60\u8bc6\u522b\u6f5c\u5728\u7684\u914d\u7f6e\u95ee\u9898\uff1a<\/p>\n<\/p>\n<p><pre><code>npm doctor<\/code><\/pre>\n<\/p>\n<p><p>\u6839\u636e\u5176\u8f93\u51fa\u4fe1\u606f\uff0c\u8fdb\u884c\u76f8\u5e94\u8c03\u6574\u3002<\/p>\n<\/p>\n<p><h3>\u6ce8\u610f\u4e8b\u9879\u548c\u5b9e\u7528\u6280\u5de7<\/h3>\n<\/p>\n<ul>\n<li><strong>\u5b9a\u671f\u66f4\u65b0 npm\uff1a<\/strong>\u4fdd\u6301 npm \u7248\u672c\u66f4\u65b0\uff0c\u53ef\u4ee5\u6700\u5927\u9650\u5ea6\u51cf\u5c11\u7531\u4e8e\u7248\u672c\u8fc7\u65e7\u5bfc\u81f4\u7684\u5b89\u88c5\u95ee\u9898\u3002<\/li>\n<li><strong>\u4f7f\u7528 nvm \u7ba1\u7406 Node.js \u7248\u672c\uff1a<\/strong>\u4f7f\u7528 Node Version Manager (NVM) \u53ef\u4ee5\u65b9\u4fbf\u5730\u7ba1\u7406\u591a\u7248\u672c Node.js\uff0c\u907f\u514d\u56e0\u7248\u672c\u4e0d\u517c\u5bb9\u5bfc\u81f4\u7684\u95ee\u9898\u3002<\/li>\n<li><strong>\u5907\u4efd\u91cd\u8981\u6587\u4ef6\uff1a<\/strong>\u8fdb\u884c\u64cd\u4f5c\u65f6\uff0c\u8981\u786e\u4fdd\u5728\u4fee\u6539\u6216\u5220\u9664\u6587\u4ef6\u4e4b\u524d\u6709\u5907\u4efd\uff0c\u8fd9\u6837\u4fbf\u4e8e\u6062\u590d\u3002<\/li>\n<li><strong>\u4f7f\u7528 Yarn \u4f5c\u4e3a\u66ff\u4ee3\uff1a<\/strong>\u5982\u679c npm \u9891\u7e41\u51fa\u73b0\u95ee\u9898\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528 Yarn \u4f5c\u4e3a\u66ff\u4ee3\uff0c\u5b83\u662f\u4e00\u4e2a\u66f4\u5feb\u901f\u3001\u66f4\u53ef\u9760\u7684\u5305\u7ba1\u7406\u5de5\u5177\u3002<\/li>\n<\/ul>\n<p><h3>\u5c0f\u7ed3<\/h3>\n<\/p>\n<p><p>\u672c\u6587\u5217\u51fa\u4e86\u591a\u4e2a\u53ef\u80fd\u9020\u6210 <strong>npm install<\/strong> \u5361\u4f4f\u7684\u539f\u56e0\uff0c\u5e76\u9488\u5bf9\u6bcf\u4e2a\u539f\u56e0\u63d0\u4f9b\u4e86\u8be6\u7ec6\u7684\u89e3\u51b3\u65b9\u6848\u548c\u64cd\u4f5c\u6b65\u9aa4\u3002\u901a\u8fc7\u6309\u7167\u672c\u6587\u7684\u65b9\u6cd5\u8fdb\u884c\u6392\u67e5\u548c\u4fee\u590d\uff0c\u5927\u591a\u6570 <strong>npm install<\/strong> \u5361\u4f4f\u7684\u95ee\u9898\u90fd\u80fd\u5f97\u5230\u6709\u6548\u89e3\u51b3\u3002\u5e0c\u671b\u8fd9\u4e9b\u4fe1\u606f\u80fd\u591f\u5e2e\u52a9\u4f60\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u907f\u514d\u8fd9\u4e9b\u70e6\u607c\uff0c\u987a\u5229\u8fdb\u884c\u9879\u76ee\u5f00\u53d1\u3002<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>npm install \u4e00\u76f4\u5361\u4f4f\u7684\u539f\u56e0\u548c\u89e3\u51b3\u65b9\u6848 \u5728\u4f7f\u7528 Node.js \u5f00\u53d1\u9879\u76ee\u65f6\uff0cnpm install \u547d\u4ee4\u662f\u975e\u5e38\u5e38\u89c1\u7684\uff0c\u7528\u4e8e\u5b89\u88c5\u4f9d\u8d56\u5305\u3002\u7136\u800c\uff0c\u6709\u65f6\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u51fa\u73b0\u5361\u4f4f\u7684\u60c5\u51b5\uff0c\u5bfc\u81f4\u65e0\u6cd5\u6b63\u5e38\u5b89\u88c5\u4f9d\u8d56\u3002\u672c\u6587\u5c06\u6df1\u5165\u63a2\u8ba8\u9020\u6210 npm insta&#8230;<\/p>\n","protected":false},"author":1,"featured_media":254,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[145,143,144],"topic":[],"class_list":["post-253","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jiushu","tag-install","tag-npm","tag-144"],"_links":{"self":[{"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/posts\/253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/comments?post=253"}],"version-history":[{"count":1,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/posts\/253\/revisions"}],"predecessor-version":[{"id":256,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/posts\/253\/revisions\/256"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/media\/254"}],"wp:attachment":[{"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/media?parent=253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/categories?post=253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/tags?post=253"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/topic?post=253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}