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

Shopify Online Store 2.0启动脚本无法进入liquid目录问题求助

Shopify主题开发脚本执行异常问题解决

问题现象

使用JS打包工具开发Shopify主题,所有Shopify内容放在独立的liquid文件夹中。原package.json的start脚本:

"start": "cd liquid && shopify switch --store=my-store.myshopify.com && shopify theme serve"

升级到Online Store 2.0后调整为:

"start": "cd liquid && shopify theme dev --store=my-store.myshopify.com"

脚本执行时提示未在主题目录运行,但手动执行cd liquid再运行shopify theme dev --store=my-store.myshopify.com却能正常工作。

原因分析

shopify theme dev命令的工作目录检测逻辑和旧版shopify theme serve存在差异:

  • 旧版命令会严格继承cd后的目录上下文
  • 新版shopify theme dev在某些npm脚本的执行环境中,可能会优先读取npm启动时的根目录,而非cd切换后的子目录(和npm脚本的shell执行机制有关,部分环境下&&连接的命令并未完全继承前序命令的目录上下文)

解决方法

方法1:用子shell包裹命令

将整个命令放在括号中,强制所有命令在子shell中执行,确保目录切换的上下文持续生效:

"start": "(cd liquid && shopify theme dev --store=my-store.myshopify.com)"

方法2:直接指定主题目录路径

无需切换目录,通过--path参数直接告知命令主题所在的liquid文件夹位置:

"start": "shopify theme dev --store=my-store.myshopify.com --path=./liquid"

方法3:指定脚本执行的shell

如果是Windows环境或shell兼容问题,可在package.json中明确指定使用bash执行脚本(需确保系统已安装bash):

"scripts": {
  "start": "cd liquid && shopify theme dev --store=my-store.myshopify.com"
},
"config": {
  "shell": "bash"
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.22 16:27:05