git bash和cmd 导致npm环境变量问题

我在win10上安装到了node.js、git
并且也配置了环境变量

在cmd下npm等命令都生效

npm config ls
; cli configs
user-agent = "npm/2.15.9 node/v4.6.1 win32 x64"

cache = "F:\\software\\NodeJS\\node_cache"
prefix = "F:\\software\\NodeJS\\node_global"

也安装了bower,是全局安装 -g

bower help

Usage:
    bower <command> [<args>] [<options>]
Commands:
    cache                   Manage bower cache
    help                    Display help information about Bower
    home                    Opens a package homepage into your favorite browser
    info                    Info of a particular package
    init                    Interactively create a bower.json file

但是再用git bash使用bower的时候发现找不到模块,奇怪的是git查找的路径是git安装目录,并不是设置的prefix = "F:\software\NodeJS\node_global"

$ bower help
module.js:327
    throw err;
    ^

Error: Cannot find module 'F:\software\Git\Git\node_modules\bower\bin\bower'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)
    at node.js:974:3

如何才能让cmd和git bash统一环境变量?

阅读 6.4k
4 个回答

再在 git-bash 里面 npm config set prefix 一遍。

C:\Users\你的用户名(全局安装的bower则是Administrator文件夹)\AppData\Roaming\npm\node_modules\bower\bin 加入到环境变量里面即可

我也曾经有过类似问题,用cmd可以找到bower相关命令,而gitbash无法找到,但是过了几天再去尝试便不再有这种情况,具体原因我不太明白,可能是类似于缓存的东西存在,您可以重启电脑后看看效果如何,也许能有些帮助

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题