.NET SpaProxyLaunchCommand 不支援 pnpm 解決辦法

.NET 專案如果用 SpaProxyLaunchCommand 搭配上 pnpm 會出現錯誤的狀況,

設定檔:

<PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <IsPackable>false</IsPackable>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
        <LangVersion>default</LangVersion>
        <!-- SPA settings -->
        <SpaRoot>ClientApp\</SpaRoot>
        <DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
        <SpaProxyServerUrl>http://localhost:9000</SpaProxyServerUrl>
        <SpaProxyLaunchCommand>pnpm dev</SpaProxyLaunchCommand>

會出現以下錯誤:

info: Microsoft.AspNetCore.SpaProxy.SpaProxyLaunchManager[0]
      No SPA development server running at https://localhost:5173 found.
fail: Microsoft.AspNetCore.SpaProxy.SpaProxyLaunchManager[0]
      Failed to launch the SPA development server 'pnpm dev'.
      System.ComponentModel.Win32Exception (2): An error occurred trying to start process 'pnpm.cmd' with working directory 'C:\project\client-app\'. 지정된 파일을 찾을 수 없습니다.
         at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
         at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
         at Microsoft.AspNetCore.SpaProxy.SpaProxyLaunchManager.LaunchDevelopmentProxy()
fail: Microsoft.AspNetCore.SpaProxy.SpaProxyLaunchManager[0]
      Couldn't start the SPA development server with command 'pnpm dev'.
info: Microsoft.AspNetCore.SpaProxy.SpaProxyMiddleware[0]
      SPA proxy is not ready. Returning temporary landing page.

會出現這錯誤主要原因是因為使用了 pnpm 官方獨立安裝的方法安裝 pnpm 所產生的,如果使用 npm i -g pnpm 安裝倒是可以正常使用。

目前官方已知此問題但修正應該排到很後面了,但有網友給出了一個 workaround,利用 <SpaProxyLaunchCommand> 去叫起一個 shell 來解決:

    <SpaProxyLaunchCommand>pnpm i &amp;&amp; pnpm dev</SpaProxyLaunchCommand>
    <SpaProxyLaunchCommand Condition="$([MSBuild]::IsOsPlatform('Windows'))">cmd.exe /s /c $(SpaProxyLaunchCommand)</SpaProxyLaunchCommand>
    <SpaProxyLaunchCommand Condition="$([MSBuild]::IsOSUnixLike())">sh -c '$(SpaProxyLaunchCommand)'</SpaProxyLaunchCommand>

Ref:

Read more

GitHub SDD Tools: spec-kit

GitHub SDD Tools: spec-kit

最近很夯 SDD,然後 GitHub 也出了工具 spec-kit 來幫助開發者撰寫 SDD 文件。 這個工具可以讓你直接用自然語言來描述你的需求,然後自動生成 SDD 文件。 spec-kit 支援來幾乎現在市面上所有的 AI Coding 工具,而且一直持續在更新。 以下是目前(0.0.79)版本可用的指令以及指令的用處: * 核心指令: 指令 用途 /speckit.constitution 建立或更新專案管理原則和開發指南 /speckit.specify 建立需求和使用者故事 /speckit.plan 建立實施計劃 /speckit.tasks 生成 Task /speckit.implement 執行 Task * 選擇性指令: 指令 用途 /speckit.clarify 釐清不明確的規格,

By Mars
Debug Story

Debug Story

Ref: * 寫程式不是輸出,是內化 * Vibe Story:用敘事智能為程式碼注入生命,簡化維護 這篇主要是想紀錄一下看了Ruddy 老師的文章後想做的事情,雖然通篇的重點不是在我想做的這件事,但因為Ruddy 老師的這篇文章讓我覺得以後在排除 Bug 的時候應該要做這件事才對。 以下的內容是擷取 Ruddy 老師的內容(部分修改) 1. 記錄搜尋路徑與嘗試過的假設 => 我以為是 state 沒清,但發現是 effect 未執行 2. 為錯誤進行分類,然後標註成概念 => 這是 mutable state 的副作用問題 3. 寫一段描述該段程式的情境與原則 => Vibe Story 該段程式的情境與原則可以參考一下的要點撰寫: * 場景(Context):描述程式碼的背景與需求。 * 目標(Goal):說明功能目的。 * 挑戰與迭代(Challenges &

By Mars