[{"data":1,"prerenderedAt":424},["ShallowReactive",2],{"navigation_docs":3,"diagnostic-content-PKG0004":48},[4,8,12,16,20,24,28,32,36,40,44],{"title":5,"path":6,"stem":7},"CLI","\u002Fcli","1.cli",{"title":9,"path":10,"stem":11},"Nuxt","\u002Fnuxt","2.nuxt",{"title":13,"path":14,"stem":15},"Vue","\u002Fvue","3.vue",{"title":17,"path":18,"stem":19},"Vite","\u002Fvite","4.vite",{"title":21,"path":22,"stem":23},"Nitro","\u002Fnitro","5.nitro",{"title":25,"path":26,"stem":27},"TypeScript","\u002Ftypescript","6.typescript",{"title":29,"path":30,"stem":31},"shadcn","\u002Fshadcn","7.shadcn",{"title":33,"path":34,"stem":35},"Package","\u002Fpackage","8.package",{"title":37,"path":38,"stem":39},"Extending Doctor","\u002Fextending","9.extending",{"title":41,"path":42,"stem":43},"MCP","\u002Fmcp","9.mcp",{"title":45,"path":46,"stem":47},"Pinia","\u002Fpinia","9.pinia",{"id":49,"title":50,"body":51,"category":57,"code":412,"description":413,"docsUrl":58,"extension":414,"fix":415,"framework":416,"meta":417,"navigation":418,"pack":60,"path":419,"ruleId":61,"rulePath":62,"seo":420,"severity":63,"source":64,"sourceUrl":65,"stem":421,"why":422,"__hash__":423},"diagnostics\u002Fdiagnostics\u002FPKG0004.md","PKG0004: Guard import() of optional packages with try or .catch()",{"type":52,"value":53,"toc":402},"minimark",[54,66,71,91,95,107,111,116,119,199,202,332,336,339,370,374,386,390,398],[55,56],"rule-metadata",{"category":57,"docsUrl":58,"fix":59,"pack":60,"ruleId":61,"rulePath":62,"severity":63,"source":64,"sourceUrl":65},"dependencies","https:\u002F\u002Fesbuild.github.io\u002Fapi\u002F#non-analyzable-imports","suggestion","vite-doctor\u002Fpackage","package\u002Foptional-peer-import-in-try","\u002Fpackage\u002Frules\u002Fdependencies\u002Foptional-peer-import-in-try","warn","src\u002Frule-packs\u002Fpackage\u002Frules\u002Foptional-peer-import-in-try.ts","https:\u002F\u002Fgithub.com\u002Fonmax\u002Fvite-doctor\u002Fblob\u002Fmain\u002Fsrc\u002Frule-packs\u002Fpackage\u002Frules\u002Foptional-peer-import-in-try.ts",[67,68,70],"h2",{"id":69},"why-it-happens","Why it happens",[72,73,74,75,79,80,82,83,86,87,90],"p",{},"esbuild, and the Wrangler, Netlify, and Vite builds that use it, fails the consumer's build when an ",[76,77,78],"code",{},"import()"," names a package that is not installed. It keeps the import for run time only when the ",[76,81,78],{}," is directly awaited in a try body of the same function or has a .",[76,84,85],{},"catch()"," or two-argument .",[76,88,89],{},"then()",". A try in a caller, or a loader callback passed to a helper that catches, does not count.",[67,92,94],{"id":93},"fix","Fix",[72,96,97,98,100,101,103,104,106],{},"Directly await the ",[76,99,78],{}," of the optional package inside a try in the function that calls it, and turn a missing package into an error that names the install command. A .",[76,102,85],{}," on the ",[76,105,78],{}," also works.",[67,108,110],{"id":109},"example","Example",[112,113,115],"h3",{"id":114},"keep-the-import-of-an-optional-peer-inside-the-try","Keep the import() of an optional peer inside the try",[72,117,118],{},"Before",[120,121,126],"pre",{"className":122,"code":123,"language":124,"meta":125,"style":125},"language-js shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","export const loadForge = () => importOptional(() => import(\"forge\"), \"forge\");\n","js","",[76,127,128],{"__ignoreMap":125},[129,130,133,137,141,145,149,152,155,159,162,165,167,170,172,175,179,181,184,187,190,192,194,196],"span",{"class":131,"line":132},"line",1,[129,134,136],{"class":135},"s7zQu","export",[129,138,140],{"class":139},"spNyl"," const",[129,142,144],{"class":143},"sTEyZ"," loadForge ",[129,146,148],{"class":147},"sMK4o","=",[129,150,151],{"class":147}," ()",[129,153,154],{"class":139}," =>",[129,156,158],{"class":157},"s2Zo4"," importOptional",[129,160,161],{"class":143},"(",[129,163,164],{"class":147},"()",[129,166,154],{"class":139},[129,168,169],{"class":147}," import",[129,171,161],{"class":143},[129,173,174],{"class":147},"\"",[129,176,178],{"class":177},"sfazB","forge",[129,180,174],{"class":147},[129,182,183],{"class":143},")",[129,185,186],{"class":147},",",[129,188,189],{"class":147}," \"",[129,191,178],{"class":177},[129,193,174],{"class":147},[129,195,183],{"class":143},[129,197,198],{"class":147},";\n",[72,200,201],{},"After",[120,203,205],{"className":122,"code":204,"language":124,"meta":125,"style":125},"export async function loadForge() {\n  try {\n    return await import(\"forge\");\n  } catch (error) {\n    throw new Error(\"Install forge to use this integration\", { cause: error });\n  }\n}\n",[76,206,207,225,233,257,278,320,326],{"__ignoreMap":125},[129,208,209,211,214,217,220,222],{"class":131,"line":132},[129,210,136],{"class":135},[129,212,213],{"class":139}," async",[129,215,216],{"class":139}," function",[129,218,219],{"class":157}," loadForge",[129,221,164],{"class":147},[129,223,224],{"class":147}," {\n",[129,226,228,231],{"class":131,"line":227},2,[129,229,230],{"class":135},"  try",[129,232,224],{"class":147},[129,234,236,239,242,244,247,249,251,253,255],{"class":131,"line":235},3,[129,237,238],{"class":135},"    return",[129,240,241],{"class":135}," await",[129,243,169],{"class":147},[129,245,161],{"class":246},"swJcz",[129,248,174],{"class":147},[129,250,178],{"class":177},[129,252,174],{"class":147},[129,254,183],{"class":246},[129,256,198],{"class":147},[129,258,260,263,266,269,272,275],{"class":131,"line":259},4,[129,261,262],{"class":147},"  }",[129,264,265],{"class":135}," catch",[129,267,268],{"class":246}," (",[129,270,271],{"class":143},"error",[129,273,274],{"class":246},") ",[129,276,277],{"class":147},"{\n",[129,279,281,284,287,290,292,294,297,299,301,304,307,310,313,316,318],{"class":131,"line":280},5,[129,282,283],{"class":135},"    throw",[129,285,286],{"class":147}," new",[129,288,289],{"class":157}," Error",[129,291,161],{"class":246},[129,293,174],{"class":147},[129,295,296],{"class":177},"Install forge to use this integration",[129,298,174],{"class":147},[129,300,186],{"class":147},[129,302,303],{"class":147}," {",[129,305,306],{"class":246}," cause",[129,308,309],{"class":147},":",[129,311,312],{"class":143}," error",[129,314,315],{"class":147}," }",[129,317,183],{"class":246},[129,319,198],{"class":147},[129,321,323],{"class":131,"line":322},6,[129,324,325],{"class":147},"  }\n",[129,327,329],{"class":131,"line":328},7,[129,330,331],{"class":147},"}\n",[67,333,335],{"id":334},"verify-the-fix","Verify the fix",[72,337,338],{},"Run only this rule after editing so the report stays focused on the diagnostic you are closing:",[120,340,344],{"className":341,"code":342,"language":343,"meta":125,"style":125},"language-bash shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","pnpm vite-doctor . --extends package\u002Frecommended --rules package\u002Foptional-peer-import-in-try\n","bash",[76,345,346],{"__ignoreMap":125},[129,347,348,352,355,358,361,364,367],{"class":131,"line":132},[129,349,351],{"class":350},"sBMFI","pnpm",[129,353,354],{"class":177}," vite-doctor",[129,356,357],{"class":177}," .",[129,359,360],{"class":177}," --extends",[129,362,363],{"class":177}," package\u002Frecommended",[129,365,366],{"class":177}," --rules",[129,368,369],{"class":177}," package\u002Foptional-peer-import-in-try\n",[67,371,373],{"id":372},"useful-links","Useful links",[375,376,377],"ul",{},[378,379,380],"li",{},[381,382,385],"a",{"href":58,"rel":383},[384],"nofollow","Upstream docs",[67,387,389],{"id":388},"related-rule","Related rule",[375,391,392],{},[378,393,394],{},[381,395,396],{"href":62},[76,397,61],{},[399,400,401],"style",{},"html pre.shiki code .s7zQu, html code.shiki .s7zQu{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#89DDFF;--shiki-default-font-style:italic;--shiki-dark:#89DDFF;--shiki-dark-font-style:italic}html pre.shiki code .spNyl, html code.shiki .spNyl{--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA}html pre.shiki code .sTEyZ, html code.shiki .sTEyZ{--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8}html pre.shiki code .sMK4o, html code.shiki .sMK4o{--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF}html pre.shiki code .s2Zo4, html code.shiki .s2Zo4{--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF}html pre.shiki code .sfazB, html code.shiki .sfazB{--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .swJcz, html code.shiki .swJcz{--shiki-light:#E53935;--shiki-default:#F07178;--shiki-dark:#F07178}html pre.shiki code .sBMFI, html code.shiki .sBMFI{--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B}",{"title":125,"searchDepth":227,"depth":227,"links":403},[404,405,406,409,410,411],{"id":69,"depth":227,"text":70},{"id":93,"depth":227,"text":94},{"id":109,"depth":227,"text":110,"children":407},[408],{"id":114,"depth":235,"text":115},{"id":334,"depth":227,"text":335},{"id":372,"depth":227,"text":373},{"id":388,"depth":227,"text":389},"PKG0004","Find import() calls of optional peers and optional dependencies that no try block in the same function and no .catch() handles, in runtime JavaScript reachable from a package export.","md","Directly await the import() of the optional package inside a try in the function that calls it, and turn a missing package into an error that names the install command. A .catch() on the import() also works.","package",{},true,"\u002Fdiagnostics\u002Fpkg0004",{"title":50,"description":413},"diagnostics\u002FPKG0004","esbuild, and the Wrangler, Netlify, and Vite builds that use it, fails the consumer's build when an import() names a package that is not installed. It keeps the import for run time only when the import() is directly awaited in a try body of the same function or has a .catch() or two-argument .then(). A try in a caller, or a loader callback passed to a helper that catches, does not count.","pozi5D_50_vQPjoMTLQGJwzTEdOd85eY-zFyuu-L5JU",1795268808714]