{"id":12877,"date":"2023-10-10T21:45:40","date_gmt":"2023-10-10T13:45:40","guid":{"rendered":"https:\/\/92it.top\/?p=12877"},"modified":"2023-10-10T21:45:40","modified_gmt":"2023-10-10T13:45:40","slug":"npm%e8%af%ad%e4%b9%89%e7%89%88%e6%9c%ac%e5%8f%b7%e3%80%81package-json-%e5%92%8c-package-lock-json","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=12877","title":{"rendered":"NPM\u8bed\u4e49\u7248\u672c\u53f7\u3001package.json \u548c package-lock.json"},"content":{"rendered":"\n<p>\u8001\u89c4\u77e9\uff0c\u770b\u6587\u7ae0\u524d\u5148\u7b54\u4e2a\u9898\uff1a<\/p>\n\n\n\n<p>\u6211\u521a\u521a\u4f7f\u7528 create-react-app \u65b0\u5efa\u4e86\u4e00\u4e2a React \u9879\u76ee\uff0c\u5176\u4e2dpackage.json\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\n  \"name\": \"playground\",\n  \"version\": \"0.1.0\",\n  \"private\": true,\n  \"dependencies\": {\n    \"@testing-library\/jest-dom\": \"^5.11.9\",\n    \"@testing-library\/react\": \"^11.2.3\",\n    \"@testing-library\/user-event\": \"^12.6.0\",\n    \"react\": \"^17.0.1\",\n    \"react-dom\": \"^17.0.1\",\n    \"react-scripts\": \"4.0.1\",\n    \"web-vitals\": \"^0.2.4\"\n  },\n  \/\/ ... \n}\n\n<\/pre>\n\n\n\n<p>\u4ee5\u4e0a\u7684<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\"react-dom\": \"^17.0.1\"<\/pre>\n\n\n\n<p>\u610f\u5473\u7740\u5b89\u88c5\u7684 react-dom \u7248\u672c\u662f\u4ec0\u4e48\u5462\uff1f<\/p>\n\n\n\n<p><strong>\u524d\u8a00<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u63d0\u8d77 npm\uff0c\u5927\u5bb6\u7b2c\u4e00\u4e2a\u60f3\u5230\u7684\u5e94\u8be5\u5c31\u662f npm install \u4e86\uff0c\u4f46\u662f npm install \u4e4b\u540e\u751f\u6210\u7684 node_modules \u5927\u5bb6\u6709\u89c2\u5bdf\u8fc7\u5417\uff1fpackage-lock.json \u6587\u4ef6\u7684\u4f5c\u7528\u5927\u5bb6\u77e5\u9053\u5417\uff1f\u9664\u4e86 dependencies \u548c devDependencies\uff0c\u5176\u4ed6\u7684\u4f9d\u8d56\u6709\u4ec0\u4e48\u4f5c\u7528\u5462\uff1f\u63a5\u4e0b\u6765\uff0c\u672c\u6587\u5c06\u9488\u5bf9 npm \u4e2d\u7684\u4f60\u53ef\u80fd\u5ffd\u7565\u7684\u7ec6\u8282\u548c\u5927\u5bb6\u5206\u4eab\u4e00\u4e9b\u7ecf\u9a8c\u3002<\/p>\n\n\n\n<p><strong>npm \u5b89\u88c5\u673a\u5236<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>A \u548c B \u540c\u65f6\u4f9d\u8d56 C\uff0cC \u8fd9\u4e2a\u5305\u4f1a\u88ab\u5b89\u88c5\u5728\u54ea\u91cc\u5462\uff1fC \u7684\u7248\u672c\u76f8\u540c\u548c\u7248\u672c\u4e0d\u540c\u65f6\u5b89\u88c5\u4f1a\u6709\u4ec0\u4e48\u5dee\u5f02\u5462\uff1fpackage.json \u4e2d\u5305\u7684\u524d\u540e\u987a\u5e8f\u5bf9\u4e8e\u5b89\u88c5\u65f6\u6709\u4ec0\u4e48\u5f71\u54cd\u5417\uff1f\u8fd9\u4e9b\u95ee\u9898\u5e73\u65f6\u5927\u5bb6\u53ef\u80fd\u6ca1\u6709\u6ce8\u610f\u8fc7\uff0c\u4eca\u5929\u6211\u4eec\u5c31\u6765\u4e00\u8d77\u7814\u7a76\u4e00\u4e0b\u5427\u3002<br>A \u548c B \u540c\u65f6\u4f9d\u8d56 C\uff0c\u8fd9\u4e2a\u5305\u4f1a\u88ab\u5b89\u88c5\u5728\u54ea\u91cc\u5462\uff1f<\/p>\n\n\n\n<p>\u5047\u5982\u6709 A \u548c B \u4e24\u4e2a\u5305\uff0c\u4e24\u4e2a\u5305\u90fd\u4f9d\u8d56 C \u8fd9\u4e2a\u5305\uff0cnpm 2 \u4f1a\u4f9d\u6b21\u9012\u5f52\u5b89\u88c5 A \u548c B \u4e24\u4e2a\u5305\u53ca\u5176\u5b50\u4f9d\u8d56\u5305\u5230 node_modules \u4e2d\u3002\u6267\u884c\u5b8c\u6bd5\u540e\uff0c\u6211\u4eec\u4f1a\u770b\u5230 .\/node_modules \u8fd9\u5c42\u76ee\u5f55\u53ea\u542b\u6709\u8fd9\u4e24\u4e2a\u5b50\u76ee\u5f55\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">node_modules\/\n\u251c\u2500\u252c A\n\u2502 \u251c\u2500\u2500 C\n\u251c\u2500\u252c B\n\u2502 \u2514\u2500\u2500 C<\/pre>\n\n\n\n<p>\u5982\u679c\u4f7f\u7528 npm 3 \u6765\u8fdb\u884c\u5b89\u88c5\u7684\u8bdd\uff0c.\/node_modules \u4e0b\u7684\u76ee\u5f55\u5c06\u4f1a\u5305\u542b\u4e09\u4e2a\u5b50\u76ee\u5f55\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">node_modules\/\n\u251c\u2500\u252c A\n\u251c\u2500\u252c B\n\u251c\u2500\u252c C<\/pre>\n\n\n\n<p>\u4e3a\u4ec0\u4e48\u4f1a\u51fa\u73b0\u8fd9\u6837\u7684\u533a\u522b\u5462\uff1f\u8fd9\u5c31\u8981\u4ece npm \u7684\u5de5\u4f5c\u65b9\u5f0f\u8bf4\u8d77\u4e86\uff1a<\/p>\n\n\n\n<p><strong>npm 2 \u548c npm 3 \u6a21\u5757\u5b89\u88c5\u673a\u5236\u7684\u5dee\u5f02<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u867d\u7136\u76ee\u524d\u6700\u65b0\u7684 npm \u7248\u672c\u662f npm 6\uff0c\u4f46 npm 2 \u5230 npm 3 \u7684\u7248\u672c\u53d8\u66f4\u4e2d\u5b9e\u73b0\u4e86\u76ee\u5f55\u6253\u5e73\uff0c\u4e0e\u5176\u4ed6\u7248\u672c\u76f8\u6bd4\u5dee\u522b\u8f83\u5927\u3002\u56e0\u6b64\uff0c\u8ba9\u6211\u4eec\u5177\u4f53\u770b\u4e0b\u8fd9\u4e24\u4e2a\u7248\u672c\u7684\u5dee\u5f02\u3002<\/p>\n\n\n\n<p>npm 2 \u5728\u5b89\u88c5\u4f9d\u8d56\u5305\u65f6\uff0c\u91c7\u7528\u7b80\u5355\u7684\u9012\u5f52\u5b89\u88c5\u65b9\u6cd5\u3002\u6267\u884c npm install \u540e\uff0cnpm \u6839\u636e dependencies \u548c devDependencies \u5c5e\u6027\u4e2d\u6307\u5b9a\u7684\u5305\u6765\u786e\u5b9a\u7b2c\u4e00\u5c42\u4f9d\u8d56\uff0cnpm 2 \u4f1a\u6839\u636e\u7b2c\u4e00\u5c42\u4f9d\u8d56\u7684\u5b50\u4f9d\u8d56\uff0c\u9012\u5f52\u5b89\u88c5\u5404\u4e2a\u5305\u5230\u5b50\u4f9d\u8d56\u7684 node_modules \u4e2d\uff0c\u76f4\u5230\u5b50\u4f9d\u8d56\u4e0d\u518d\u4f9d\u8d56\u5176\u4ed6\u6a21\u5757\u3002\u6267\u884c\u5b8c\u6bd5\u540e\uff0c\u6211\u4eec\u4f1a\u770b\u5230 .\/node_modules \u8fd9\u5c42\u76ee\u5f55\u4e2d\u5305\u542b\u6709\u6211\u4eec package.json \u6587\u4ef6\u4e2d\u6240\u6709\u7684\u4f9d\u8d56\u5305\uff0c\u800c\u8fd9\u4e9b\u4f9d\u8d56\u5305\u7684\u5b50\u4f9d\u8d56\u5305\u90fd\u5b89\u88c5\u5728\u4e86\u81ea\u5df1\u7684 node_modules \u4e2d \uff0c\u5f62\u6210\u7c7b\u4f3c\u4e8e\u4e0b\u9762\u7684\u4f9d\u8d56\u6811\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"405\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-10-1024x405.png\" alt=\"\" class=\"wp-image-12879\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-10-1024x405.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-10-300x119.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-10-768x303.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-10-1536x607.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-10-830x328.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-10-230x91.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-10-350x138.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-10-480x190.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-10.png 1610w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u8fd9\u6837\u7684\u76ee\u5f55\u6709\u8f83\u4e3a\u660e\u663e\u7684\u597d\u5904\uff1a<\/p>\n\n\n\n<p>1\uff09\u5c42\u7ea7\u7ed3\u6784\u975e\u5e38\u660e\u663e\uff0c\u53ef\u4ee5\u6e05\u695a\u7684\u5728\u7b2c\u4e00\u5c42\u7684 node_modules \u4e2d\u770b\u5230\u6211\u4eec\u5b89\u88c5\u7684\u6240\u6709\u5305\u7684\u5b50\u76ee\u5f55\uff1b<\/p>\n\n\n\n<p>2\uff09\u5728\u5df2\u77e5\u81ea\u5df1\u6240\u9700\u5305\u7684\u540d\u5b57\u4ee5\u53ca\u7248\u672c\u53f7\u65f6\uff0c\u53ef\u4ee5\u590d\u5236\u7c98\u8d34\u76f8\u5e94\u7684\u6587\u4ef6\u5230 node_modules \u4e2d\uff0c\u7136\u540e\u624b\u52a8\u66f4\u6539 package.json \u4e2d\u7684\u914d\u7f6e\uff1b<\/p>\n\n\n\n<p>3\uff09\u5982\u679c\u60f3\u8981\u5220\u9664\u67d0\u4e2a\u5305\uff0c\u53ea\u9700\u8981\u7b80\u5355\u7684\u5220\u9664 package.json \u6587\u4ef6\u4e2d\u76f8\u5e94\u7684\u67d0\u4e00\u884c\uff0c\u7136\u540e\u5220\u9664 node_modules \u4e2d\u8be5\u5305\u7684\u76ee\u5f55\uff1b<\/p>\n\n\n\n<p>\u4f46\u662f\u8fd9\u6837\u7684\u5c42\u7ea7\u7ed3\u6784\u4e5f\u6709\u8f83\u4e3a\u660e\u663e\u7684\u7f3a\u9677\uff0c\u5f53\u6211\u7684 A\uff0cB\uff0cC \u4e09\u4e2a\u5305\u4e2d\u6709\u76f8\u540c\u7684\u4f9d\u8d56 D \u65f6\uff0c\u6267\u884c npm install \u540e\uff0cD \u4f1a\u88ab\u91cd\u590d\u4e0b\u8f7d\u4e09\u6b21\uff0c\u800c\u968f\u7740\u6211\u4eec\u7684\u9879\u76ee\u8d8a\u6765\u8d8a\u590d\u6742\uff0cnode_modules \u4e2d\u7684\u4f9d\u8d56\u6811\u4e5f\u4f1a\u8d8a\u6765\u8d8a\u590d\u6742\uff0c\u50cf D \u8fd9\u6837\u7684\u5305\u4e5f\u4f1a\u8d8a\u6765\u8d8a\u591a\uff0c\u9020\u6210\u4e86\u5927\u91cf\u7684\u5197\u4f59\uff1b\u5728 windows \u7cfb\u7edf\u4e2d\uff0c\u751a\u81f3\u4f1a\u56e0\u4e3a\u76ee\u5f55\u7684\u5c42\u7ea7\u592a\u6df1\u5bfc\u81f4\u6587\u4ef6\u7684\u8def\u5f84\u8fc7\u957f\uff0c\u89e6\u53d1\u6587\u4ef6\u8def\u5f84\u4e0d\u80fd\u8d85\u8fc7 280 \u4e2a\u5b57\u7b26\u7684\u9519\u8bef\uff1b<\/p>\n\n\n\n<p>\u4e3a\u4e86\u89e3\u51b3\u4ee5\u4e0a\u95ee\u9898\uff0cnpm 3 \u7684 node_modules \u76ee\u5f55\u6539\u6210\u4e86\u66f4\u4e3a\u6241\u5e73\u72b6\u7684\u5c42\u7ea7\u7ed3\u6784\uff0c\u5c3d\u91cf\u628a\u4f9d\u8d56\u4ee5\u53ca\u4f9d\u8d56\u7684\u4f9d\u8d56\u5e73\u94fa\u5728 node_modules \u6587\u4ef6\u5939\u4e0b\u5171\u4eab\u4f7f\u7528\u3002<\/p>\n\n\n\n<p><strong>npm 3 \u5bf9\u4e8e\u540c\u4e00\u4f9d\u8d56\u7684\u4e0d\u540c\u7248\u672c\u4f1a\u600e\u4e48\u5904\u7406\u5462\uff1f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>npm 3 \u4f1a\u904d\u5386\u6240\u6709\u7684\u8282\u70b9\uff0c\u9010\u4e2a\u5c06\u6a21\u5757\u653e\u5728 node_modules \u7684\u7b2c\u4e00\u5c42\uff0c\u5f53\u53d1\u73b0\u6709\u91cd\u590d\u6a21\u5757\u65f6\uff0c\u5219\u4e22\u5f03\uff0c \u5982\u679c\u9047\u5230\u67d0\u4e9b\u4f9d\u8d56\u7248\u672c\u4e0d\u517c\u5bb9\u7684\u95ee\u9898\uff0c\u5219\u7ee7\u7eed\u91c7\u7528 npm 2 \u7684\u5904\u7406\u65b9\u5f0f\uff0c\u524d\u9762\u7684\u653e\u5728 node_modules \u76ee\u5f55\u4e2d\uff0c\u540e\u9762\u7684\u653e\u5728\u4f9d\u8d56\u6811\u4e2d\u3002\u4e3e\u4e2a????\uff1aA\uff0cB\uff0c\u4f9d\u8d56 D(v 0.0.1)\uff0cC \u4f9d\u8d56 D(v 0.0.2):<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-11-1024x520.png\" alt=\"\" class=\"wp-image-12880\" width=\"464\" height=\"235\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-11-1024x520.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-11-300x152.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-11-768x390.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-11-830x422.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-11-230x117.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-11-350x178.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-11-480x244.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-11.png 1216w\" sizes=\"(max-width: 464px) 100vw, 464px\" \/><\/figure><\/div>\n\n\n\n<p>\u4f46\u662f npm 3 \u4f1a\u5e26\u6765\u4e00\u4e2a\u65b0\u7684\u95ee\u9898\uff1a\u7531\u4e8e\u5728\u6267\u884c npm install \u7684\u65f6\u5019\uff0c\u6309\u7167 package.json \u91cc\u4f9d\u8d56\u7684\u987a\u5e8f\u4f9d\u6b21\u89e3\u6790\uff0c\u4e0a\u56fe\u5982\u679c C \u7684\u987a\u5e8f\u5728 A\uff0cB \u7684\u524d\u8fb9\uff0cnode_modules \u6811\u5219\u4f1a\u6539\u53d8\uff0c\u4f1a\u51fa\u73b0\u4e0b\u8fb9\u7684\u60c5\u51b5\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-12-1024x484.png\" alt=\"\" class=\"wp-image-12881\" width=\"421\" height=\"199\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-12-1024x484.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-12-300x142.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-12-768x363.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-12-830x393.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-12-230x109.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-12-350x166.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-12-480x227.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-12.png 1154w\" sizes=\"(max-width: 421px) 100vw, 421px\" \/><\/figure><\/div>\n\n\n\n<p>\u7531\u6b64\u53ef\u89c1\uff0cnpm 3 \u5e76\u672a\u5b8c\u5168\u89e3\u51b3\u5197\u4f59\u7684\u95ee\u9898\uff0c\u751a\u81f3\u8fd8\u4f1a\u5e26\u6765\u65b0\u7684\u95ee\u9898\u3002<\/p>\n\n\n\n<p><strong>NPM\u8bed\u4e49\u7248\u672c\u53f7<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u5728 <a rel=\"noreferrer noopener\" href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/docs.npmjs.com\/about-semantic-versioning\" target=\"_blank\">npm \u7684\u5b98\u65b9\u6587\u6863<\/a>\u4e2d\u5efa\u8bae\u5e93\u7684\u7248\u672c\u53f7\u7684\u53d1\u5e03\u89c4\u5219\u5982\u4e0b \uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>\u573a\u666f<\/th><th>\u9636\u6bb5<\/th><th>\u89c4\u5219<\/th><th>\u4f8b\u5b50<\/th><\/tr><tr><td>\u9996\u6b21\u53d1\u5e03<\/td><td>\u65b0\u4ea7\u54c1<\/td><td>\u4ece 1.0.0 \u5f00\u59cb<\/td><td>1.0.0<\/td><\/tr><tr><td>\u5411\u540e\u517c\u5bb9\u7684bug\u4fee\u590d<\/td><td>\u53d1\u5e03\u8865\u4e01<\/td><td>\u7b2c\u4e09\u4f4d\u6570\u5b57\u503c\u9012\u589e<\/td><td>1.0.1<\/td><\/tr><tr><td>\u5411\u540e\u517c\u5bb9\u7684\u65b0\u7279\u6027<\/td><td>\u5c0f\u7248\u672c\u66f4\u65b0<\/td><td>\u7b2c\u4e8c\u4f4d\u6570\u5b57\u9012\u589e\u4e14\u5c06\u7b2c\u4e09\u4f4d\u6570\u5b57\u91cd\u7f6e\u4e3a0<\/td><td>1.1.0<\/td><\/tr><tr><td>\u7834\u574f\u5411\u540e\u517c\u5bb9\u7684\u4fee\u6539<\/td><td>\u5927\u7248\u672c\u66f4\u65b0<\/td><td>\u7b2c\u4e00\u4f4d\u6570\u5b57\u9012\u589e\u4e14\u5c06\u7b2c\u4e8c\u3001\u4e09\u4e3a\u6570\u5b57\u91cd\u7f6e\u4e3a0<\/td><td>2.0.0<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u4ee5\u4e0a\u7684\u89c4\u5219\u53ef\u4ee5\u7b80\u5355\u603b\u7ed3\u4e3a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-9.png\" alt=\"\" class=\"wp-image-12878\" width=\"228\" height=\"169\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-9.png 964w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-9-300x223.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-9-768x572.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-9-830x618.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-9-230x171.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-9-350x261.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-9-480x358.png 480w\" sizes=\"(max-width: 228px) 100vw, 228px\" \/><\/figure><\/div>\n\n\n\n<p>\u5f53\u7136\uff0c\u7406\u60f3\u5f88\u4e30\u6ee1\uff0c\u73b0\u5b9e\u5f88\u9aa8\u611f~ \u5f88\u591a\u7b2c\u4e09\u65b9\u5e93\u7684\u7248\u672c\u53f7\u5e76\u6ca1\u6709\u4e25\u683c\u6309\u7167\u4ee5\u4e0a\u7684\u89c4\u5219\u53d1\u5e03\uff0c\u56e0\u6b64\u4e5f\u9020\u6210\u4e86\u4e00\u4e9b\u201c\u8f66\u7978\u201d\u3002\uff08\u7b2c\u4e09\u90e8\u5206\u4f1a\u5206\u4eab\u6211\u7684\u6848\u4f8b\uff09<\/p>\n\n\n\n<p><strong>\u4f60\u60f3\u4f7f\u7528\u4ec0\u4e48\u7248\u672c\uff1f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u56de\u770b\u6587\u7ae0\u5f00\u5934\u6211\u4f7f\u7528 create-react-app \u65b0\u5efa\u7684\u9879\u76ee\u91cc package.json \u91cc\u7684<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\"react-scripts\": \"4.0.1\"<\/pre>\n\n\n\n<p>\u8fd9\u8fb9\u975e\u5e38\u660e\u786e\u5730\u6307\u5b9a\u4e86\u4f7f\u7528 react-scripts \u7684 4.0.1 \u7248\u672c\u3002<\/p>\n\n\n\n<p>\u6240\u6709\u4f9d\u8d56\u5e93\u90fd\u4f7f\u7528\u8fd9\u6837\u660e\u786e\u7684\u7248\u672c\u58f0\u660e\u4e0d\u597d\u5417\uff1f\u2014\u2014 \u662f\u7684\uff0c\u8fd9\u53ef\u80fd\u4e0d\u662f\u6700\u4f73\u7684\u505a\u6cd5\u3002<\/p>\n\n\n\n<p>\u8bbe\u60f3\uff0c\u4f60\u7684\u9879\u76ee\u91cc\u4f9d\u8d56\u7684\u67d0\u4e2a\u5e93\u6709\u4e2a\u6027\u80fd\u95ee\u9898\uff0c\u4f5c\u8005\u6700\u8fd1\u53d1\u5e03\u4e86\u4fee\u590d\u8865\u4e01\uff0c\u5982\u679c\u4f60\u4e0d\u662f\u7ecf\u5e38\u5173\u6ce8\u8be5\u5e93\u7684 changelog\uff0c\u4f60\u53ef\u80fd\u6839\u672c\u4e0d\u77e5\u9053\uff0c\u4f60\u7684\u9879\u76ee\u4e5f\u4eab\u53d7\u4e0d\u5230\u8fd9\u4e2a\u6027\u80fd\u63d0\u5347\u4e86\u3002<\/p>\n\n\n\n<p>\u518d\u8bbe\u60f3\uff0c\u4f60\u7684\u9879\u76ee\u91cc\u4f9d\u8d56\u7684\u67d0\u4e2a\u5e93\u6700\u8fd1\u88ab\u4f5c\u8005\u66f4\u65b0\u4e86\uff0c\u63d0\u4f9b\u4e86\u51e0\u4e2a\u5341\u5206\u6709\u7528\u7684\u5c0f\u529f\u80fd\uff0c\u540c\u6837\u7684\uff0c\u4f7f\u7528\u7cbe\u786e\u7684\u7248\u672c\u53f7\u4e0d\u80fd\u8ba9\u4f60\u53ca\u65f6\u4f53\u9a8c\u5230\u8fd9\u4e9b\u65b0\u7279\u6027\u3002<\/p>\n\n\n\n<p>\u90a3\u4e48\u6709\u529e\u6cd5\u8bbe\u7f6e\u4e00\u4e2a\u6a21\u7cca\u7684\u7248\u672c\u53f7\u8303\u56f4\u5417\uff1f \u2014\u2014 \u6709\u7684\uff01\u4e0b\u9762\u4f7f\u7528\u4f8b\u5b50\u6765\u66f4\u597d\u5730\u8bf4\u660e<\/p>\n\n\n\n<ul><li>1\uff09 \u53ca\u65f6\u5e2e\u6211\u5b89\u88c5\u6700\u65b0\u8865\u4e01<\/li><\/ul>\n\n\n\n<p>\u4f8b\u5b501\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\"some-lib\": \"1.0\"   \n\u6216   \n\"some-lib\": \"1.0.x\"<\/pre>\n\n\n\n<p>\u8bf4\u660e1\uff1a npm install \u7684\u65f6\u5019\uff0c\u8bf7\u5e2e\u6211\u5b89\u88c5 1.0 \u7684\u5c0f\u7248\u672c\u4ee5\u53ca\u6700\u65b0\u7684\u8865\u4e01\u7248\u672c\uff0c\u5982 1.0.2 , 1.0.6 \u7b49<\/p>\n\n\n\n<p>\u4f8b\u5b502:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\"some-lib\"\uff1a \u201d~1.0.4\u201c <\/pre>\n\n\n\n<p>\u8bf4\u660e2: npm install \u7684\u65f6\u5019\uff0c\u8bf7\u5e2e\u6211\u5b89\u88c5 1.0 \u7684\u5c0f\u7248\u672c \u4ee5\u53ca <strong>1.0.4 \u4ee5\u4e0a<\/strong>\u7684\u6700\u65b0\u8865\u4e01\u7248\u672c\uff0c \u5982 1.0.6 \u7b49\uff08\u4f46\u4e0d\u4f1a\u5b89\u88c5 1.0.2 \u56e0\u4e3a\u5b83\u4f4e\u4e8e 1.0.4 \uff09<\/p>\n\n\n\n<ul><li>2\uff09\u53ca\u65f6\u5e2e\u6211\u5b89\u88c5\u6700\u65b0\u5c0f\u7248\u672c\u548c\u6700\u65b0\u8865\u4e01<\/li><\/ul>\n\n\n\n<p>\u4f8b\u5b503:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\"some-lib\": \"1\"   \n\u6216   \n\"some-lib\": \"1.x\"<\/pre>\n\n\n\n<p>\u8bf4\u660e3: npm install \u7684\u65f6\u5019\uff0c\u8bf7\u5e2e\u6211\u5b89\u88c5 1 \u7684\u5927\u7248\u672c\u4ee5\u53ca\u6700\u65b0\u7684\u5c0f\u7248\u672c\u4ee5\u53ca\u8865\u4e01\u7248\u672c\uff0c\u5982 1.0.6 , 1.1.6 , 1.2.3 , 1.3.0 \u7b49<\/p>\n\n\n\n<p>\u4f8b\u5b504:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\"some-lib\": \"^1.1.4\" <\/pre>\n\n\n\n<p>\u8bf4\u660e4: npm install \u7684\u65f6\u5019\uff0c\u8bf7\u5e2e\u6211\u5b89\u88c5 1 \u7684\u5927\u7248\u672c\u4ee5\u53ca <strong>1.1.4 \u4ee5\u4e0a <\/strong>\u6700\u65b0\u7684\u5c0f\u7248\u672c\u4ee5\u53ca\u8865\u4e01\u7248\u672c\uff0c\u5982 1.1.6 , 1.2.3 , 1.3.0 \u7b49 \uff08\u4f46\u4e0d\u4f1a\u5b89\u88c5 1.0.6 \u56e0\u4e3a\u5b83\u4f4e\u4e8e 1.1.4 \uff09<\/p>\n\n\n\n<ul><li>3) \u53ca\u65f6\u5e2e\u6211\u5b89\u88c5\u6700\u65b0\u7684\u7248\u672c<\/li><\/ul>\n\n\n\n<p>\u4f8b\u5b505:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\"some-lib\": \"*\"   \n\u6216   \n\"some-lib\": \"x\"<\/pre>\n\n\n\n<p>\u8bf4\u660e5: npm install \u7684\u65f6\u5019, <strong>\u90fd\u7ed9\u6211\u5b89\u88c5\u6700\u6700\u6700\u65b0\u7684\u7248\u672c\uff01\u6211\u4e0d\u5728\u4e4e\u517c\u5bb9\u6027\uff01\u9879\u76ee\u4e0a\u7ebf\u5d29\u76d8\u4e86\u6211\u4e5f\u65e0\u6240\u8c13\uff01<\/strong> \u2014\u2014 \u8fd9\u662f\u6700\u6d6e\u5938\u7684\u4e00\u79cd\u5199\u6cd5\uff0c\u5f53\u7136\u4e5f\u662f\u57fa\u672c\u4e0d\u53ef\u80fd\u51fa\u73b0\u5728\u5b9e\u9645\u751f\u4ea7\u73af\u5883\u4ee3\u7801\u4e2d\u7684\u5199\u6cd5\u3002<\/p>\n\n\n\n<p>\uff08\u4ee5\u4e0a\u90fd\u662f\u4ee5\u9879\u76ee\u4e2d\u6ca1\u6709 package-lock.json \u4e3a\u524d\u63d0\u5047\u8bbe\uff0c\u540e\u9762\u7684\u7ae0\u8282\u4f1a\u8c08\u5230 package-lock.json\uff09<\/p>\n\n\n\n<p>\u5b98\u65b9\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5b9e\u9a8c\u5e73\u53f0\u7f51\u7ad9\u53ef\u4ee5\u5c1d\u8bd5\u4ee5\u4e0a\u8fd9\u4e9b\u5199\u6cd5 <a href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/semver.npmjs.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">npm semantic version calculator<\/a><\/p>\n\n\n\n<p>\u770b\u5230\u8fd9\u91cc\uff0c\u4f60\u5e94\u8be5\u5c31\u80fd\u56de\u7b54\u51fa\u6587\u7ae0\u5f00\u5934\u7684\u90a3\u4e2a\u95ee\u9898\u4e86\u5427<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    \"react-dom\": \"^17.0.1\" \u5b89\u88c5\u7684\u662f\u4ec0\u4e48\u7248\u672c\uff1f<\/pre>\n\n\n\n<p><strong>\u4e3a\u4ec0\u4e48\u4f1a\u51fa\u73b0 package-lock.json \u5462\uff1f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u4e3a\u4ec0\u4e48\u4f1a\u6709 package-lock.json \u6587\u4ef6\u5462\uff1f\u8fd9\u4e2a\u6211\u4eec\u5c31\u8981\u5148\u4ece package.json \u6587\u4ef6\u8bf4\u8d77\u4e86\u3002<\/p>\n\n\n\n<ul><li><strong>package.json \u7684\u4e0d\u8db3\u4e4b\u5904<\/strong><\/li><\/ul>\n\n\n\n<p>npm install \u6267\u884c\u540e\uff0c\u4f1a\u751f\u6210\u4e00\u4e2a node_modules \u6811\uff0c\u5728\u7406\u60f3\u60c5\u51b5\u4e0b\uff0c \u5e0c\u671b\u5bf9\u4e8e\u540c\u4e00\u4e2a package.json \u603b\u662f\u751f\u6210\u5b8c\u5168\u76f8\u540c node_modules \u6811\u3002\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u786e\u5b9e\u5982\u6b64\u3002\u4f46\u5728\u591a\u6570\u60c5\u51b5\u4e0b\uff0cnpm \u65e0\u6cd5\u505a\u5230\u8fd9\u4e00\u70b9\u3002\u6709\u4ee5\u4e0b\u4e24\u4e2a\u539f\u56e0\uff1a<\/p>\n\n\n\n<p>1\uff09\u67d0\u4e9b\u4f9d\u8d56\u9879\u81ea\u4e0a\u6b21\u5b89\u88c5\u4ee5\u6765\uff0c\u53ef\u80fd\u5df2\u53d1\u5e03\u4e86\u65b0\u7248\u672c \u3002\u6bd4\u5982\uff1aA \u5305\u5728\u56e2\u961f\u4e2d\u7b2c\u4e00\u4e2a\u4eba\u5b89\u88c5\u7684\u65f6\u5019\u662f 1.0.5 \u7248\u672c\uff0cpackage.json \u4e2d\u7684\u914d\u7f6e\u9879\u4e3a A: &#8216;^1.0.5&#8217;\uff1b\u56e2\u961f\u4e2d\u7b2c\u4e8c\u4e2a\u4eba\u628a\u4ee3\u7801\u62c9\u4e0b\u6765\u7684\u65f6\u5019\uff0cA \u5305\u7684\u7248\u672c\u5df2\u7ecf\u5347\u7ea7\u6210\u4e86 1.0.8\uff0c\u6839\u636e package.json \u4e2d\u7684 semver-range version \u89c4\u8303\uff0c\u6b64\u65f6\u7b2c\u4e8c\u4e2a\u4eba npm install \u540e A \u7684\u7248\u672c\u4e3a 1.0.8\uff1b\u53ef\u80fd\u4f1a\u9020\u6210\u56e0\u4e3a\u4f9d\u8d56\u7248\u672c\u4e0d\u540c\u800c\u5bfc\u81f4\u7684 bug\uff1b<\/p>\n\n\n\n<p>2\uff09\u9488\u5bf9 1\uff09\u4e2d\u7684\u95ee\u9898\uff0c\u53ef\u80fd\u6709\u7684\u5c0f\u4f19\u4f34\u4f1a\u662f\u628a A \u7684\u7248\u672c\u53f7\u56fa\u5b9a\u4e3a A: &#8216;1.0.5&#8217; \u4e0d\u5c31\u53ef\u4ee5\u4e86\u5417\uff1f\u4f46\u662f\u8fd9\u6837\u7684\u505a\u6cd5\u5176\u5b9e\u5e76\u6ca1\u6709\u89e3\u51b3\u95ee\u9898\uff0c \u6bd4\u5982 A \u7684\u67d0\u4e2a\u4f9d\u8d56\u5728\u7b2c\u4e00\u4e2a\u4eba\u4e0b\u8f7d\u7684\u65f6\u5019\u662f 2.1.3 \u7248\u672c\uff0c\u4f46\u662f\u7b2c\u4e8c\u4e2a\u4eba\u4e0b\u8f7d\u7684\u65f6\u5019\u5df2\u7ecf\u5347\u7ea7\u5230\u4e86 2.2.5 \u7248\u672c\uff0c\u6b64\u65f6\u751f\u6210\u7684 node_modules \u6811\u4f9d\u65e7\u4e0d\u5b8c\u5168\u76f8\u540c \uff0c\u56fa\u5b9a\u7248\u672c\u53ea\u662f\u56fa\u5b9a\u6765\u81ea\u8eab\u7684\u7248\u672c\uff0c\u4f9d\u8d56\u7684\u7248\u672c\u65e0\u6cd5\u56fa\u5b9a\u3002<\/p>\n\n\n\n<ul><li><strong>\u9488\u5bf9 package.json \u4e0d\u8db3\u7684\u89e3\u51b3\u65b9\u6cd5<\/strong><\/li><\/ul>\n\n\n\n<p>\u4e3a\u4e86\u89e3\u51b3\u4e0a\u8ff0\u95ee\u9898\u4ee5\u53ca npm 3 \u7684\u95ee\u9898\uff0c\u5728 npm 5.0 \u7248\u672c\u540e\uff0cnpm install \u540e\u90fd\u4f1a\u81ea\u52a8\u751f\u6210\u4e00\u4e2a package-lock.json \u6587\u4ef6 \uff0c\u5f53\u5305\u4e2d\u6709 package-lock.json \u6587\u4ef6\u65f6\uff0cnpm install \u6267\u884c\u65f6\uff0c\u5982\u679c package.json \u548c package-lock.json \u4e2d\u7684\u7248\u672c\u517c\u5bb9\uff0c\u4f1a\u6839\u636e package-lock.json \u4e2d\u7684\u7248\u672c\u4e0b\u8f7d\uff1b\u5982\u679c\u4e0d\u517c\u5bb9\uff0c\u5c06\u4f1a\u6839\u636e package.json \u7684\u7248\u672c\uff0c\u66f4\u65b0 package-lock.json \u4e2d\u7684\u7248\u672c\uff0c\u5df2\u4fdd\u8bc1 package-lock.json \u4e2d\u7684\u7248\u672c\u517c\u5bb9 package.json\u3002<\/p>\n\n\n\n<ul><li><strong>package-lock.json \u6587\u4ef6\u7684\u7ed3\u6784<\/strong><\/li><\/ul>\n\n\n\n<p>package-lock.json \u6587\u4ef6\u4e2d\u7684 name\u3001version \u4e0e package.json \u4e2d\u7684 name\u3001version \u4e00\u6837\uff0c\u63cf\u8ff0\u4e86\u5f53\u524d\u5305\u7684\u540d\u5b57\u548c\u7248\u672c\uff0cdependencies \u662f\u4e00\u4e2a\u5bf9\u8c61\uff0c\u8be5\u5bf9\u8c61\u548c node_modules \u4e2d\u7684\u5305\u7ed3\u6784\u4e00\u4e00\u5bf9\u5e94\uff0c\u5bf9\u8c61\u7684 key \u4e3a\u5305\u7684\u540d\u79f0\uff0c\u503c\u4e3a\u5305\u7684\u4e00\u4e9b\u63cf\u8ff0\u4fe1\u606f\uff0c \u6839\u636e package-lock-json\u5b98\u65b9\u6587\u6863 (https:\/\/docs.npmjs.com\/configuring-npm\/package-lock-json.html#requires)\uff0c\u4e3b\u8981\u7684\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">version \uff1a\u5305\u7248\u672c\uff0c\u5373\u8fd9\u4e2a\u5305\u5f53\u524d\u5b89\u88c5\u5728 node_modules \u4e2d\u7684\u7248\u672c\nresolved \uff1a\u5305\u5177\u4f53\u7684\u5b89\u88c5\u6765\u6e90\nintegrity \uff1a\u5305 hash \u503c\uff0c\u9a8c\u8bc1\u5df2\u5b89\u88c5\u7684\u8f6f\u4ef6\u5305\u662f\u5426\u88ab\u6539\u52a8\u8fc7\u3001\u662f\u5426\u5df2\u5931\u6548\nrequires \uff1a\u5bf9\u5e94\u5b50\u4f9d\u8d56\u7684\u4f9d\u8d56\uff0c\u4e0e\u5b50\u4f9d\u8d56\u7684 package.json \u4e2d dependencies \u7684\u4f9d\u8d56\u9879\u76f8\u540c\ndependencies \uff1a\u7ed3\u6784\u548c\u5916\u5c42\u7684 dependencies \u7ed3\u6784\u76f8\u540c\uff0c\u5b58\u50a8\u5b89\u88c5\u5728\u5b50\u4f9d\u8d56 node_modules \u4e2d\u7684\u4f9d\u8d56\u5305\n<\/pre>\n\n\n\n<ul><li><strong>package-lock.json \u6587\u4ef6\u7684\u4f5c\u7528<\/strong><\/li><\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\u5728\u56e2\u961f\u5f00\u53d1\u4e2d\uff0c\u786e\u4fdd\u6bcf\u4e2a\u56e2\u961f\u6210\u5458\u5b89\u88c5\u7684\u4f9d\u8d56\u7248\u672c\u662f\u4e00\u81f4\u7684\uff0c\u786e\u5b9a\u4e00\u68f5\u552f\u4e00\u7684 node_modules \u6811\uff1b\nnode_modules \u76ee\u5f55\u672c\u8eab\u662f\u4e0d\u4f1a\u88ab\u63d0\u4ea4\u5230\u4ee3\u7801\u5e93\u7684\uff0c\u4f46\u662f package-lock.json \u53ef\u4ee5\u63d0\u4ea4\u5230\u4ee3\u7801\u5e93\uff0c\u5982\u679c\u5f00\u53d1\u4eba\u5458\u60f3\u8981\u56de\u6eaf\u5230\u67d0\u4e00\u5929\u7684\u76ee\u5f55\u72b6\u6001\uff0c\u53ea\u9700\u8981\u628a package.json \u548c package-lock.json \u8fd9\u4e24\u4e2a\u6587\u4ef6\u56de\u9000\u5230\u90a3\u4e00\u5929\u5373\u53ef\u3002\n\u7531\u4e8e package-lock.json \u548c node_modules \u4e2d\u7684\u4f9d\u8d56\u5d4c\u5957\u5b8c\u5168\u4e00\u81f4\uff0c\u53ef\u4ee5\u66f4\u52a0\u6e05\u695a\u7684\u4e86\u89e3\u6811\u7684\u7ed3\u6784\u53ca\u5176\u53d8\u5316\u3002\n\u5728\u5b89\u88c5\u65f6\uff0cnpm \u4f1a\u6bd4\u8f83 node_modules \u5df2\u6709\u7684\u5305\uff0c\u548c package-lock.json \u8fdb\u884c\u6bd4\u8f83\uff0c\u5982\u679c\u91cd\u590d\u7684\u8bdd\uff0c\u5c31\u8df3\u8fc7\u5b89\u88c5 \uff0c\u4ece\u800c\u4f18\u5316\u4e86\u5b89\u88c5\u7684\u8fc7\u7a0b\u3002\n<\/pre>\n\n\n\n<p><strong>\u4f9d\u8d56\u7684\u533a\u522b\u4e0e\u4f7f\u7528\u573a\u666f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>npm \u76ee\u524d\u652f\u6301\u4ee5\u4e0b\u51e0\u7c7b\u4f9d\u8d56\u5305\u7ba1\u7406\u5305\u62ec<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">dependencies\ndevDependencies\noptionalDependencies \u53ef\u9009\u62e9\u7684\u4f9d\u8d56\u5305\npeerDependencies \u540c\u7b49\u4f9d\u8d56\nbundledDependencies \u6346\u7ed1\u4f9d\u8d56\u5305<\/pre>\n\n\n\n<p><strong>dependencies<\/strong><\/p>\n\n\n\n<p>dependencies \u662f\u65e0\u8bba\u5728\u5f00\u53d1\u73af\u5883\u8fd8\u662f\u5728\u751f\u4ea7\u73af\u5883\u90fd\u5fc5\u987b\u4f7f\u7528\u7684\u4f9d\u8d56\uff0c\u662f\u6211\u4eec\u6700\u5e38\u7528\u7684\u4f9d\u8d56\u5305\u7ba1\u7406\u5bf9\u8c61\uff0c\u4f8b\u5982 React\uff0cLoadsh\uff0cAxios \u7b49\uff0c\u901a\u8fc7 npm install XXX \u4e0b\u8f7d\u7684\u5305\u90fd\u4f1a\u9ed8\u8ba4\u5b89\u88c5\u5728 dependencies \u5bf9\u8c61\u4e2d\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528 npm install XXX &#8211;save \u4e0b\u8f7d dependencies \u4e2d\u7684\u5305\uff1b<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-13-1024x400.png\" alt=\"\" class=\"wp-image-12882\" width=\"459\" height=\"179\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-13-1024x400.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-13-300x117.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-13-768x300.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-13-830x324.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-13-230x90.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-13-350x137.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-13-480x187.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-13.png 1086w\" sizes=\"(max-width: 459px) 100vw, 459px\" \/><\/figure><\/div>\n\n\n\n<p><strong>devDependencies<\/strong><\/p>\n\n\n\n<p>devDependencies \u662f\u6307\u53ef\u4ee5\u5728\u5f00\u53d1\u73af\u5883\u4f7f\u7528\u7684\u4f9d\u8d56\uff0c\u4f8b\u5982 eslint\uff0cdebug \u7b49\uff0c\u901a\u8fc7 npm install packageName &#8211;save-dev \u4e0b\u8f7d\u7684\u5305\u90fd\u4f1a\u5728 devDependencies \u5bf9\u8c61\u4e2d\uff1b<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-14-1024x423.png\" alt=\"\" class=\"wp-image-12883\" width=\"450\" height=\"185\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-14-1024x423.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-14-300x124.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-14-768x317.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-14-830x343.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-14-230x95.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-14-350x144.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-14-480x198.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/10\/\u56fe\u7247-14.png 1216w\" sizes=\"(max-width: 450px) 100vw, 450px\" \/><\/figure><\/div>\n\n\n\n<p>dependencies \u548c devDependencies \u6700\u5927\u7684\u533a\u522b\u662f\u5728\u6253\u5305\u8fd0\u884c\u65f6\uff0c\u6267\u884c npm install \u65f6\u9ed8\u8ba4\u4f1a\u628a\u6240\u6709\u4f9d\u8d56\u5168\u90e8\u5b89\u88c5\uff0c\u4f46\u662f\u5982\u679c\u4f7f\u7528 npm install &#8211;production \u65f6\u5c31\u53ea\u4f1a\u5b89\u88c5 dependencies \u4e2d\u7684\u4f9d\u8d56\uff0c\u5982\u679c\u662f node \u670d\u52a1\u9879\u76ee\uff0c\u5c31\u53ef\u4ee5\u91c7\u7528\u8fd9\u6837\u7684\u65b9\u5f0f\u7528\u4e8e\u670d\u52a1\u8fd0\u884c\u65f6\u5b89\u88c5\u548c\u6253\u5305\uff0c\u51cf\u5c11\u5305\u5927\u5c0f\u3002<\/p>\n\n\n\n<p><strong>\u6211\u5230\u5e95\u5b89\u88c5\u4e86\u54ea\u4e2a\u7248\u672c\uff1f\u2014\u2014 package-lock.json<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>package.json \u91cc\u58f0\u660e\u7684\u7248\u672c\u652f\u6301\u4ee5\u4e0a\u7684\u6a21\u7cca\u5199\u6cd5\uff0c\u90a3\u4e48\u5728 npm install \u7684\u65f6\u5019\uff0c\u6211\u600e\u4e48\u77e5\u9053\u5230\u5e95\u5b89\u88c5\u4e86\u5177\u4f53\u54ea\u4e2a\u7248\u672c\u5462\uff1f<\/p>\n\n\n\n<p>\u7b54\u6848\u5c31\u5728 package-lock.json \u91cc\uff0c\u5728\u6211\u7684\u6d4b\u8bd5\u9879\u76ee\u7684 package-lock.json \u6709\u4ee5\u4e0b\u5185\u5bb9<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">...\n    \"react-dom\": {\n      \"version\": \"17.0.1\",\n      \"resolved\": \"https:\/\/registry.npmjs.org\/react-dom\/-\/react-dom-17.0.1.tgz\",\n      \"integrity\": \"sha512-6eV150oJZ9U2t9svnsspTMrWNyHc6chX0KzDeAOXftRa8bNeOKTTfCJ7KorIwenkHd2xqVTBTCZd79yk\/lx\/Ug==\",\n      \"requires\": {\n        \"loose-envify\": \"^1.1.0\",\n        \"object-assign\": \"^4.1.1\",\n        \"scheduler\": \"^0.20.1\"\n      }\n    },\n...<\/pre>\n\n\n\n<p>\u7531\u6b64\u53ef\u4ee5\u77e5\u9053 \u5f53\u524d\u5b89\u88c5\u7684react-dom \u7684\u7cbe\u786e\u7248\u672c\u662f 17.0.1<\/p>\n\n\n\n<p>package-lock.json \u8fd8\u6709\u4e00\u4e2a\u5f88\u91cd\u8981\u7684\u4f5c\u7528 \u2014\u2014 \u5f53 npm install \u65f6\u53d1\u73b0\u672c\u5730\u6709 package-lock.json\uff0c\u5c31\u4f1a\u4e25\u683c\u6309\u7167 package-lock.json \u7684\u7248\u672c\u6765\u5b89\u88c5\u3002<\/p>\n\n\n\n<ul><li>package-lock.json \u5b8c\u6574\u63cf\u8ff0\u4e86\u5f53\u524d\u9879\u76ee\u7684\u4f9d\u8d56\u6811\uff0c\u4fdd\u8bc1\u4e86\u5176\u4ed6\u5730\u65b9\u8fd0\u884cnpm install \u65f6\u90fd\u80fd\u5b89\u88c5\u4e00\u6a21\u4e00\u6837\u7684\u4f9d\u8d56\u5e93\u7248\u672c<\/li><li>\u65e0\u9700\u628a node_modules \u4e0a\u4f20\u5230Git\u5c31\u80fd\u8fbe\u5230\u4e0a\u9762\u7b2c\u4e00\u70b9\u63d0\u5230\u7684\u6548\u679c<\/li><li>\u5982\u679cpackage-lock.json\u66f4\u65b0\u5e76\u4e0a\u4f20\u65b0\u7248\u672c\u5230 Git\uff0c\u5229\u7528 Git \u7684 Diff \u529f\u80fd\u53ef\u4ee5\u6e05\u695a\u5730\u4e86\u89e3\u53d1\u751f\u4e86\u54ea\u4e9b\u53d8\u5316\u53ef\u4ee5\u8ba9 Npm install \u65f6\u8df3\u8fc7\u5bf9\u4e00\u4e9b\u4f9d\u8d56\u5e93\u7684\u5143\u6570\u636e\u7684\u8bf7\u6c42\uff0c\u4f18\u5316\u4e86\u6027\u80fd<\/li><li>\u4ece npm v7 \u7248\u672c\u5f00\u59cb\uff0cpackage-lock.json \u7684\u4fe1\u606f\u5df2\u7ecf\u5305\u542b\u4e86 package.json \u5173\u4e8e\u4f9d\u8d56\u6811\u7684\u7684\u6240\u6709\u5185\u5bb9\uff0c\u56e0\u6b64\u65e0\u9700\u518d\u89e3\u6790 package.json\uff0c\u5927\u5927\u63d0\u9ad8\u4e86\u6027\u80fd<\/li><\/ul>\n\n\n\n<p><strong>\u5b9e\u8df5\u9047\u5230\u7684\u5751<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u9879\u76ee\u91cc\u5f88\u65e9\u4e4b\u524d\u5c31\u5f15\u7528\u4e86\u67d0\u4e2a\u5e93 lib-a\uff0c\u5728dependency\u91cc\u4f7f\u7528\u7684\u7248\u672c\u53f7\u662f \u201d^1.0.4&#8243; \u3002<\/p>\n\n\n\n<p>\u67d0\u6b21\u4e0a\u7ebf\u540e\uff0c\u7279\u5b9a\u9875\u9762\u51fa\u73b0 bug\uff0c\u4f46\u662f\u5728\u6211\u7535\u8111\u672c\u5730\u65e0\u6cd5\u590d\u73b0\u540c\u6837\u7684\u95ee\u9898\u3002\u4e8e\u662f\u6211\u6e05\u9664 node_modules \u6587\u4ef6\u5939\u548c package-lock.json \uff0c\u91cd\u65b0\u6267\u884c npm install \u5e76\u8fd0\u884c\u9879\u76ee\uff0c\u8fd9\u6b21\u590d\u73b0\u4e86\u95ee\u9898\u3002<\/p>\n\n\n\n<p>\u6839\u636e\u9519\u8bef\u65e5\u5fd7\uff0c\u8ffd\u6eaf\u5230\u4e86\u95ee\u9898\u5728\u4e8e lib-a \u91cc\u3002<\/p>\n\n\n\n<p>\u5bf9\u6bd4\u4e86\u524d\u540e\u7684 package-lock.json \u7684\u5185\u5bb9\uff0c\u53d1\u73b0\u65b0\u5b89\u88c5\u7684 lib-a \u7684\u7248\u672c\u662f 1.0.5 \u800c\u4e4b\u524d\u4e00\u76f4\u662f 1.0.4 \uff0c\u770b\u6765 1.0.5 \u662f\u6709 bug \u7684\u3002<\/p>\n\n\n\n<p>\u4f46\u662f\u4e3a\u4ec0\u4e48\u7ebf\u4e0a\u4f1a\u5b89\u88c5 1.0.5 \u5462\uff1f\u539f\u6765 package-lock.json \u56e0\u4e3a\u67d0\u4e9b\u5386\u53f2\u539f\u56e0\u88ab\u52a0\u5165\u5230\u4e86 .gitignore \u91cc\uff0c\u5bfc\u81f4\u7ebf\u4e0a\u90e8\u7f72\u7684 npm install \u65f6\u6ca1\u6709 package-lock.json\u9650\u5236 \u5c31\u5b89\u88c5\u4e86lib-a\u7684\u6700\u65b0\u7684\u7248\u672c\u3002<\/p>\n\n\n\n<p>\u67e5\u660e\u539f\u56e0\u540e\uff0c\u6211\u5728dependency\u91cc\u76f4\u63a5\u58f0\u660e\u4e86\u51c6\u786e\u7684\u7248\u672c\u53f7 1.0.4 \u89e3\u51b3\u4e86\u95ee\u9898\u3002<\/p>\n\n\n\n<p>\u5410\u69fd\uff1a<\/p>\n\n\n\n<p>\u7406\u8bba\u4e0a 1.0.5 \u53ea\u662f 1.0.4 \u7684\u8865\u4e01\u7248\u672c\uff0c\u4e3a\u4ec0\u4e48\u53cd\u800c\u5bfc\u81f4\u4e86 bug \uff01<\/p>\n\n\n\n<p>\u8fd9\u5c31\u662f\u9aa8\u611f\u7684\u73b0\u5b9e \u2014\u2014 \u4e0d\u662f\u6240\u6709\u5e93\u7684\u8865\u4e01\/\u5c0f\u7248\u672c\u90fd\u4e0d\u4f1a\u7834\u574f\u5411\u540e\u517c\u5bb9\uff0c\u90fd\u53ef\u80fd\u51fa\u95ee\u9898\u3002<\/p>\n\n\n\n<p>\u56e0\u6b64\uff0c\u8fd9\u6b21\u5f97\u5230\u7684\u6559\u8bad\u662f<strong> \u5c3d\u91cf\u5c06 package-lock.json \u4e0a\u4f20\u5230 git \u4e0a\uff1b\u5982\u679c\u8ffd\u6c42\u7a33\u5b9a\uff0c\u751a\u81f3\u53ef\u4ee5\u4f7f\u7528\u7cbe\u51c6\u7248\u672c\u53f7\uff1b\u5c3d\u91cf\u591a\u4f7f\u7528\u5355\u5143\u6d4b\u8bd5\u548c\u96c6\u6210\u6d4b\u8bd5\u53ca\u65f6\u53d1\u73b0\u95ee\u9898\u3002<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8001\u89c4\u77e9\uff0c\u770b\u6587\u7ae0\u524d\u5148\u7b54\u4e2a\u9898\uff1a \u6211\u521a\u521a\u4f7f\u7528 create-react-app \u65b0\u5efa\u4e86\u4e00\u4e2a React \u9879\u76ee\uff0c\u5176\u4e2dp [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/12877"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12877"}],"version-history":[{"count":2,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/12877\/revisions"}],"predecessor-version":[{"id":12885,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/12877\/revisions\/12885"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12877"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12877"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12877"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}