强制节点在 Windows 上使用 git bash

2024-04-28

我有一个 package.json 文件,如下所示:

{
  "name": "APP",
  "version": "3.0.0",
  "private": true,
  "scripts": {
    "start": "node app.js",
    "test": "./test/dbLoad && env db=test test=1 jasmine"
  }
}

当我运行 npm test 时,出现错误:

'.' is not recognized as an internal or external command

我猜这是因为节点正在使用 Windowscmd.exe。如果我用它作为前缀,该命令就可以正常工作bash。我可以更改节点中的某种配置设置,以便它自动使用 bash 吗?


设置 NPMscript-shell指向 Git Bash(注意较新的路径):

npm config set script-shell "C:\\Program Files\\Git\\bin\\bash.exe"

这告诉 NPM 运行您定义的脚本package.json(例如start or test) 使用指定的 shell 而不是默认的 shell,在 Windows 上是cmd.exe. See https://docs.npmjs.com/misc/config#script-shell https://docs.npmjs.com/misc/config#script-shell.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

强制节点在 Windows 上使用 git bash 的相关文章

随机推荐