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兼容的命令:
打开
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" }将
build命令替换为:"build": "md dist 2>nul && copy index.html dist\\ && copy index.js dist\\",md dist 2>nul:创建dist目录,2>nul用来忽略目录已存在的错误提示copy:Windows系统的文件复制命令,路径分隔符用\\
保存文件后,重新执行
yarn watch即可正常运行。
备选方案
如果你习惯使用Unix命令,可以通过Git Bash、WSL(Windows Subsystem for Linux)或者PowerShell来执行原命令,这些环境支持mkdir -p和cp语法。
内容的提问来源于stack exchange,提问作者Software Engineer
相关产品推荐
相关产品推荐

