How come npm install doesn't work on git bash

前端 未结 13 1194
天涯浪人
天涯浪人 2020-12-07 19:00

I have git bash open and I type in npm install and then it returns:

bash: npm command not found

I don\'t understand, because I

相关标签:
13条回答
  • 2020-12-07 19:48

    Assuming you are on Windows trying git-bash, and node was installed by Visual Studio: The cause may be a missing npm bash script.

    There is an npm.cmd bath file in the path:

    C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External\npm.cmd
    

    But git bash wont run .cmd files. So you need to create a bash script for npm.

    Create the following file named npm in your node folder: (C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External\)

    #!/bin/sh
    basedir=`dirname "$0"`
    
    case `uname` in
        *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
    esac
    
    if [ -x "$basedir/node" ]; then
      "$basedir/node"  "$basedir/node_modules/npm/bin/npm-cli.js" "$@"
      ret=$?
    else 
      node  "$basedir/node_modules/npm/bin/npm-cli.js" "$@"
      ret=$?
    fi
    exit $ret
    
    0 讨论(0)
提交回复
热议问题