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

Windows10执行npm run test提示'.'不是内部或外部命令如何解决

问题原因
  • 路径格式不兼容:你当前使用Windows 10系统,CMD/PowerShell默认无法识别Unix风格的./开头的相对路径写法,scripts中./node_modules/.bin/mocha的写法会被系统误将.识别为独立命令,触发报错。
  • 冗余路径前缀:npm执行scripts脚本时会自动将项目内node_modules/.bin目录加入临时环境变量,无需手动写全可执行文件路径。
解决方案

最优方案(跨平台通用)

直接删除scripts中mocha命令的前缀路径,修改后的package.json scripts字段如下:

{
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "mocha ./src/spec/mocha-specs --recursive --reporter spec",
    "test:part2": "mocha ./src/spec/mocha-specs/part2/ --recursive --reporter spec",
    "test:part3": "mocha ./src/spec/mocha-specs/part3/ --recursive --reporter spec"
  }
}

该写法适配Windows、Linux、macOS全平台,无需针对系统单独调整。

注意事项

  • 原package.json中三个test脚本末尾多了冗余逗号,修改时建议删除,避免JSON格式校验报错。
  • 如果修改后执行npm run test提示mocha 不是内部或外部命令,执行npm install mocha -D将mocha安装到项目开发依赖即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.28 10:45:01