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

Tensorflow.js入门教程执行yarn watch命令报错求助

解决Windows下yarn watch执行报错问题

错误原因

你的build命令使用了Unix/Linux环境的mkdir -p和cp命令,Windows命令提示符(cmd)不支持这些语法,导致出现「The syntax of the command is incorrect」错误。

解决方案

修改项目根目录下package.json中的build脚本,替换为Windows兼容的命令:

  1. 打开package.json,找到scripts区块里的build命令:

    "scripts": {
      "build": "mkdir -p dist/ && cp index.html dist/ && cp index.js dist/",
      "watch": "npm run build && node_modules/http-server/bin/http-server dist -p 1234"
    }
    
  2. 将build命令替换为:

    "build": "md dist 2>nul && copy index.html dist\\ && copy index.js dist\\",
    
    • md dist 2>nul:创建dist目录,2>nul用来忽略目录已存在的错误提示
    • copy:Windows系统的文件复制命令,路径分隔符用\\
  3. 保存文件后,重新执行yarn watch即可正常运行。

备选方案

如果你习惯使用Unix命令,可以通过Git Bash、WSL(Windows Subsystem for Linux)或者PowerShell来执行原命令,这些环境支持mkdir -p和cp语法。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 17:07:01