Skip to content

Error on windows commit (hook: line 49: : command not found) #139

Description

@FreelancerA13

I'am having trouble using pre-commit, 1.2.2. When i try to commit i have an error
./node_modules/pre-commit/hook: line 49: : command not found

win 8, Intelij Idea 2016 (with integrated git), npm 6.1.0, node v10.6.0

Activity

  1. sarbbottam commented on Sep 24, 2018

    @sarbbottam

    I just faced the similar issue in our CI system. node is not available in the $PATH, any node command is proxied via another executable, something like cmd node script.js

    I am wondering if we could do something like

    if [[ $* == *--dry-run* ]]; then
      exit 1
    else
      if [[ -z "$BINARY" ]]; then
        exit 1
      fi
      "$BINARY" "$("$BINARY" -e "console.log(require.resolve('pre-commit'))")"
    fi
    

    instead of

    if [[ $* == *--dry-run* ]]; then
      if [[ -z "$BINARY" ]]; then
        exit 1
      fi
    else
      "$BINARY" "$("$BINARY" -e "console.log(require.resolve('pre-commit'))")"
    fi
    

    at https://github.com/observing/pre-commit/blob/master/hook?

    Please excuse my ignorance, if I am oversimplifying it.

    Happy to raise a PR, if this is an accepted solution.

  2. BeatriceThalo commented on Oct 30, 2018

    @BeatriceThalo

    same error, ubuntu 18.04, vs code 1.28.2-1539735992, nvm 0.33.5, node v8.12.0, npm 6.4.1, git 2.19.1, pre-commit 1.2.2

  3. BeatriceThalo commented on Nov 8, 2018

    @BeatriceThalo

    fixed it by editing the file:
    .git/hooks/pre-commit

    to include the line:
    . $HOME/.nvm/nvm.sh

    for example:

    #!/bin/bash
    . $HOME/.nvm/nvm.sh
    ./node_modules/pre-commit/hook
    RESULT=$?
    [ $RESULT -ne 0 ] && exit 1
    exit 0
    
  4. vince1995 commented on Feb 5, 2019

    @vince1995

    I just solved this problem:

    Install nodejs on Windows, then add a .bashrc file in your home (C:/users/YOUR_PROFILE) dir and add PATH=$PATH:/c/Program\ Files/nodejs. That's it.

    @3rd-Eden maybe you could add this info to the readme?

  5. kumarashwin commented on May 13, 2019

    @kumarashwin

    I was having a similar issue trying to commit within VS Code in Ubuntu 18.04.

    Just chiming in so that this helps someone else that end's up searching after having this issue


    When using n for your Node Version Management, if you run into this issue, I was able to resolve it by adding PATH=$PATH:$HOME/n/bin to the first line of my .git/hooks/pre-commit file.

    It now looks like this:

    #!/bin/bash
    PATH=$PATH:$HOME/n/bin
    ./node_modules/pre-commit/hook
    RESULT=$?
    [ $RESULT -ne 0 ] && exit 1
    exit 0
    
  6. wll8 commented on Nov 10, 2019

    @wll8

    The same problem.

  7. stringang commented on Dec 16, 2019

    @stringang

    Windows10 git bash setting environment variables can solve the problem.

    $ vim ~/.bashrc
    # add in .bashrc
    PATH=$PATH:/c/Program\ Files\ \(x86\)/nodejs
  8. bennycode commented on Feb 9, 2020

    @bennycode

    I also had the following issue:

    git push origin && git push origin --tags && npm publish

    .git/hooks/pre-push: line 8: dirname: command not found
    .git/hooks/pre-push: line 8: /husky.sh: No such file or directory

    error: failed to push some refs to 'git@github.com:bennyn/my-repository.git'

    I fixed it by adding "C:\Program Files\Git\cmd" to my %PATH% system variable (Windows 10). My Git version is: 2.24.0.windows.2

    image

  9. ryanmaffey commented on Jul 13, 2021

    @ryanmaffey

    Had this issue recently and it seemed to be related to using nvm-windows

    Fixed this issue by making sure the following were included in the System Variables > Path (the definitions were already present in the User Variables Path):

    • %NVM_HOME%
    • %NVM_SYMLINK%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions