You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker脚本报‘bare " in non-quoted-field’错误的排查求助

问题原因与解决方案

核心问题

PowerShell Core(.NET Core 7环境)与Windows PowerShell在外部程序参数传递的引号转义逻辑上存在差异,再加上WSL环境下Docker对路径格式的要求,导致原脚本参数解析失败:

  • 原脚本中src="$path\src/..."的双引号嵌套写法,在PowerShell Core中会将转义符\和引号一起传递给Docker,触发bare " in non-quoted-field错误。
  • WSL环境下的Docker更兼容类Unix风格的正斜杠(/)路径,而非Windows的反斜杠(\)。

解决方法

修改--mount参数的路径写法,去掉src值的嵌套引号,并统一使用正斜杠:

param (
    [string]$target = "build"
)    

Write-Host "Running npm run $target"
$path = (Get-Item -Path ".\").FullName

# 将Windows反斜杠替换为类Unix正斜杠
$path = $path -replace "\\", "/"

docker run -it --memory="500m" --memory-swap="1g" --rm `
                --mount type=bind,src=$path/src/MyProject/wwwroot/dist,dst=/work/wwwroot/dist `
                --mount type=bind,src=$path/src/MyProject/fed/dist,dst=/work/fed/dist `
                --mount type=bind,src=$path/src/MyProject/fed/.storybook,dst=/work/fed/.storybook `
                --mount type=bind,src=$path/src/MyProject/fed/src,dst=/work/fed/src `
                mytag npm run $target

补充说明

  • 如果路径包含空格,PowerShell Core会自动为含空格的路径添加引号传递给Docker,无需手动嵌套引号。
  • 若仍遇空格相关问题,可提前展开变量后用单引号包裹路径:
    --mount type=bind,src='$path/src/My Project/wwwroot/dist',dst=/work/wwwroot/dist
    

内容的提问来源于stack exchange,提问作者Ethan Schofer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 22:15:03