{"id":22888,"date":"2024-11-21T15:53:49","date_gmt":"2024-11-21T07:53:49","guid":{"rendered":"https:\/\/fwq.ai\/blog\/22888\/"},"modified":"2024-11-21T15:53:49","modified_gmt":"2024-11-21T07:53:49","slug":"laravel-mix-%e5%87%ba%e9%94%99","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/22888\/","title":{"rendered":"laravel mix \u51fa\u9519"},"content":{"rendered":"<p>laravel mix\u662f\u4e00\u4e2a\u975e\u5e38\u65b9\u4fbf\u6613\u7528\u7684\u81ea\u52a8\u5316\u524d\u7aef\u5de5\u5177\u3002\u5b83\u57fa\u4e8ewebpack\uff0c\u63d0\u4f9b\u4e86\u4e00\u4e9b\u7b80\u5355\u7684api\u4f7f\u5f00\u53d1\u8005\u80fd\u591f\u5feb\u901f\u7684\u7f16\u8bd1\u548c\u6253\u5305web\u5e94\u7528\u7684\u524d\u7aef\u4ee3\u7801\u3002\u5c3d\u7ba1laravel mix\u975e\u5e38\u65b9\u4fbf\uff0c\u4f46\u662f\u6709\u65f6\u5019\u8fd0\u884cmix\u4efb\u52a1\u65f6\u4f1a\u9047\u5230\u9519\u8bef\u3002\u672c\u6587\u5c06\u8ba8\u8bba\u4e00\u4e9b\u5e38\u89c1\u7684\u9519\u8bef\u53ca\u5176\u89e3\u51b3\u65b9\u6cd5\u3002<\/p>\n<ol>\n<li>Module not found: Error: Can&#8217;t resolve &#8216;xxx&#8217;<\/li>\n<\/ol>\n<p>\u8fd9\u662fLaravel Mix\u4e2d\u6700\u5e38\u89c1\u7684\u9519\u8bef\u4e4b\u4e00\u3002\u5b83\u8868\u793a\u5728\u7f16\u8bd1\u8fc7\u7a0b\u4e2d\u65e0\u6cd5\u627e\u5230\u6307\u5b9a\u7684\u6a21\u5757\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/p>\n<p>\u2460 \u786e\u8ba4\u6a21\u5757\u662f\u5426\u6b63\u786e\u5b89\u88c5\u3002\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u4f7f\u7528npm ls\u547d\u4ee4\u6765\u68c0\u67e5\u3002<\/p>\n<p>\u2461 \u786e\u8ba4\u4f60\u7684webpack.mix.js\u4e2d\u8def\u5f84\u662f\u5426\u6b63\u786e\u3002<\/p>\n<p>\u2462 \u786e\u8ba4\u662f\u4e0d\u662f\u6a21\u5757\u6ca1\u6709\u88ab\u5b89\u88c5\uff0c\u5982\u679c\u6ca1\u6709\uff0c\u5219\u9700\u8981\u8fd0\u884cnpm install xxx &#8211;save\u547d\u4ee4\u6765\u5b89\u88c5\u3002<\/p>\n<ol>\n<li>Module build failed: Error: Cannot find module &#8216;xxx&#8217;<\/li>\n<\/ol>\n<p>\u8fd9\u4e2a\u9519\u8bef\u610f\u5473\u7740\u5728\u7f16\u8bd1\u8fc7\u7a0b\u4e2dWebpack\u627e\u4e0d\u5230\u6307\u5b9a\u7684\u6a21\u5757\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/p>\n<p>\u2460 \u786e\u8ba4\u6a21\u5757\u662f\u5426\u6b63\u786e\u5b89\u88c5\u3002<\/p>\n<p>\u2461 \u786e\u8ba4Webpack\u914d\u7f6e\u4e2d\u662f\u5426\u6b63\u786e\u6307\u5b9a\u4e86\u5165\u53e3\u6587\u4ef6\u3002<\/p>\n<p>\u2462 \u6e05\u9664\u7f13\u5b58\u5e76\u91cd\u65b0\u7f16\u8bd1\u3002<\/p>\n<ol>\n<li>Syntax Error: &#8220;Unexpected token&#8221;<\/li>\n<\/ol>\n<p>\u8fd9\u4e2a\u9519\u8bef\u901a\u5e38\u51fa\u73b0\u5728\u4ee3\u7801\u4e2d\u6709\u8bed\u6cd5\u9519\u8bef\u7684\u60c5\u51b5\u4e0b\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/p>\n<p>\u2460 \u5728\u4ee3\u7801\u4e2d\u627e\u5230\u9519\u8bef<\/p>\n<p>\u2461 \u5c06\u9519\u8bef\u4fee\u590d<\/p>\n<ol>\n<li>TypeError: Cannot read property &#8216;xxx&#8217; of undefined<\/li>\n<\/ol>\n<p>\u8fd9\u4e2a\u9519\u8bef\u610f\u5473\u7740\u5728\u7f16\u8bd1\u8fc7\u7a0b\u4e2d\u6253\u5305\u7684\u4ee3\u7801\u4e2d\uff0c\u5c1d\u8bd5\u8bbf\u95ee\u4e00\u4e2a\u672a\u5b9a\u4e49\u7684\u5c5e\u6027\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/p>\n<p>\u2460 \u786e\u8ba4\u4ee3\u7801\u903b\u8f91\u662f\u5426\u6b63\u786e<\/p>\n<p>\u2461 \u786e\u8ba4\u662f\u5426\u6b63\u786e\u5b9a\u4e49\u4e86\u8be5\u5c5e\u6027<\/p>\n<ol>\n<li>Maximum call stack size exceeded<\/li>\n<\/ol>\n<p>\u8fd9\u4e2a\u9519\u8bef\u610f\u5473\u7740\u4f60\u7684\u9012\u5f52\u8c03\u7528\u8fc7\u591a\uff0c\u5bfc\u81f4\u5806\u6808\u6ea2\u51fa\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/p>\n<p>\u2460 \u901a\u8fc7\u51cf\u5c11\u9012\u5f52\u7684\u6df1\u5ea6\u6216\u4f7f\u7528forEach\u5faa\u73af\u6765\u66ff\u6362\u9012\u5f52<\/p>\n<p>\u2461 \u4f7f\u7528setImmediate\u6216\u8005setTimeout\u6765\u786e\u4fdd\u56de\u8c03\u51fd\u6570\u4e0d\u518d\u5f02\u6b65\u961f\u5217\u4e2d\u5d4c\u5957\u592a\u591a<\/p>\n<ol>\n<li>Error: Cannot find module &#8216;babel-core&#8217;<\/li>\n<\/ol>\n<p>\u8fd9\u4e2a\u9519\u8bef\u610f\u5473\u7740Babel\u6838\u5fc3\u6a21\u5757\u5df2\u88ab\u4eceNPM\u4e0a\u5220\u9664\uff0cLaravel Mix\u4f9d\u8d56\u7684\u7248\u672c\u8fc7\u671f\uff0c\u6216\u8005\u4f60\u6b63\u5728\u4f7f\u7528\u65e7\u7684Webpack\u7248\u672c\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/p>\n<p>\u2460 \u624b\u52a8\u5b89\u88c5 babel-core<\/p>\n<p>npm install babel-core &#8211;save-dev<\/p>\n<p>\u2461 \u5347\u7ea7Laravel Mix\u6216\u8005Webpack\u7248\u672c\u3002<\/p>\n<p>\u4ee5\u4e0a\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u9519\u8bef\u53ca\u5176\u89e3\u51b3\u65b9\u6cd5\u3002\u867d\u7136\u6240\u6709\u7684\u95ee\u9898\u90fd\u9700\u8981\u6839\u636e\u5177\u4f53\u60c5\u51b5\u6765\u89e3\u51b3\uff0c\u4f46\u662f\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u53ea\u9700\u8981\u4ed4\u7ec6\u68c0\u67e5\u5e76\u4e14\u6309\u7167\u4e0a\u9762\u63d0\u5230\u7684\u6b65\u9aa4\u53bb\u89e3\u51b3\u5c31\u53ef\u4ee5\u4e86\u3002Laravel Mix\u662f\u4e00\u6b3e\u975e\u5e38\u597d\u7528\u7684\u524d\u7aef\u5de5\u5177\uff0c\u53ef\u4ee5\u5927\u5927\u51cf\u8f7b\u524d\u7aef\u5f00\u53d1\u4eba\u5458\u7684\u5de5\u4f5c\u8d1f\u62c5\u3002\u6211\u4eec\u5e94\u8be5\u638c\u63e1\u4e00\u4e9b\u5e38\u89c1\u9519\u8bef\u5904\u7406\u65b9\u6cd5\uff0c\u4ee5\u4fbf\u5728\u5f00\u53d1\u4e2d\u66f4\u5feb\u66f4\u6709\u6548\u5730\u89e3\u51b3\u9519\u8bef\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662flaravel mix \u51fa\u9519\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>laravel mix\u662f\u4e00\u4e2a\u975e\u5e38\u65b9\u4fbf\u6613\u7528\u7684\u81ea\u52a8\u5316\u524d\u7aef\u5de5\u5177\u3002\u5b83\u57fa\u4e8ewebpack\uff0c\u63d0\u4f9b\u4e86\u4e00\u4e9b\u7b80\u5355\u7684api\u4f7f\u5f00\u53d1\u8005\u80fd\u591f\u5feb\u901f\u7684\u7f16\u8bd1\u548c\u6253\u5305web\u5e94\u7528\u7684\u524d\u7aef\u4ee3\u7801\u3002\u5c3d\u7ba1laravel mix\u975e\u5e38\u65b9\u4fbf\uff0c\u4f46\u662f\u6709\u65f6\u5019\u8fd0\u884cmix\u4efb\u52a1\u65f6\u4f1a\u9047\u5230\u9519\u8bef\u3002\u672c\u6587\u5c06\u8ba8\u8bba\u4e00\u4e9b\u5e38\u89c1\u7684\u9519\u8bef\u53ca\u5176\u89e3\u51b3\u65b9\u6cd5\u3002 Module not found: Error: Can&#8217;t resolve &#8216;xxx&#8217; \u8fd9\u662fLaravel Mix\u4e2d\u6700\u5e38\u89c1\u7684\u9519\u8bef\u4e4b\u4e00\u3002\u5b83\u8868\u793a\u5728\u7f16\u8bd1\u8fc7\u7a0b\u4e2d\u65e0\u6cd5\u627e\u5230\u6307\u5b9a\u7684\u6a21\u5757\u3002 \u89e3\u51b3\u65b9\u6cd5\uff1a \u2460 \u786e\u8ba4\u6a21\u5757\u662f\u5426\u6b63\u786e\u5b89\u88c5\u3002\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u4f7f\u7528npm ls\u547d\u4ee4\u6765\u68c0\u67e5\u3002 \u2461 \u786e\u8ba4\u4f60\u7684webpack.mix.js\u4e2d\u8def\u5f84\u662f\u5426\u6b63\u786e\u3002 \u2462 \u786e\u8ba4\u662f\u4e0d\u662f\u6a21\u5757\u6ca1\u6709\u88ab\u5b89\u88c5\uff0c\u5982\u679c\u6ca1\u6709\uff0c\u5219\u9700\u8981\u8fd0\u884cnpm install xxx &#8211;save\u547d\u4ee4\u6765\u5b89\u88c5\u3002 Module build failed: Error: Cannot find module &#8216;xxx&#8217; \u8fd9\u4e2a\u9519\u8bef\u610f\u5473\u7740\u5728\u7f16\u8bd1\u8fc7\u7a0b\u4e2dWebpack\u627e\u4e0d\u5230\u6307\u5b9a\u7684\u6a21\u5757\u3002 \u89e3\u51b3\u65b9\u6cd5\uff1a \u2460 \u786e\u8ba4\u6a21\u5757\u662f\u5426\u6b63\u786e\u5b89\u88c5\u3002 \u2461 \u786e\u8ba4Webpack\u914d\u7f6e\u4e2d\u662f\u5426\u6b63\u786e\u6307\u5b9a\u4e86\u5165\u53e3\u6587\u4ef6\u3002 \u2462 \u6e05\u9664\u7f13\u5b58\u5e76\u91cd\u65b0\u7f16\u8bd1\u3002 Syntax Error: &#8220;Unexpected token&#8221; \u8fd9\u4e2a\u9519\u8bef\u901a\u5e38\u51fa\u73b0\u5728\u4ee3\u7801\u4e2d\u6709\u8bed\u6cd5\u9519\u8bef\u7684\u60c5\u51b5\u4e0b\u3002 \u89e3\u51b3\u65b9\u6cd5\uff1a \u2460 \u5728\u4ee3\u7801\u4e2d\u627e\u5230\u9519\u8bef \u2461 \u5c06\u9519\u8bef\u4fee\u590d TypeError: Cannot read property &#8216;xxx&#8217; of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-22888","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22888","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=22888"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22888\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=22888"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=22888"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=22888"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}