husky: Husky failed to install with `Cannot read property 'toString' of null` message.

OS: MacOS 10.15.2 (19C57) Git: git version 2.23.0

❯ node -v v12.14.0

"husky": "^4.0.6",

During the installation i’m getting the following error.

husky > Setting up git hooks 
Cannot read property 'toString' of null 
husky > Failed to install

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 23
  • Comments: 21 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Had the same error. I run in a docker container (project files are on a shared volume). I have no git in the container, this is what I get with HUSKY_DEBUG=1

husky > Setting up git hooks husky:debug Current working directory is /opt/app/node_modules/husky Cannot read property 'toString' of null husky:debug TypeError: Cannot read property 'toString' of null at Object.checkGitVersion (/opt/app/node_modules/husky/lib/installer/checkGitVersion.js:12:32) at run (/opt/app/node_modules/husky/lib/installer/bin.js:60:31) at Object.<anonymous> (/opt/app/node_modules/husky/lib/installer/bin.js:88:1) at Module._compile (internal/modules/cjs/loader.js:956:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10) at Module.load (internal/modules/cjs/loader.js:812:32) at Function.Module._load (internal/modules/cjs/loader.js:724:14) at Module.require (internal/modules/cjs/loader.js:849:19) at require (internal/modules/cjs/helpers.js:74:18) at Object.<anonymous> (/opt/app/node_modules/husky/husky.js:20:3) husky > Failed to install

Installing git into the container fixed this issue.

happened to me also. happens only during docker container build

> husky@4.3.0 install /opt/web/node_modules/husky
> node husky install

husky > Setting up git hooks
Cannot read property 'toString' of null
husky > Failed to install

tried to use version 2.6.0 and got this error

husky > Setting up git hooks
Can't find .git, skipping Git hooks installation.
Please check that you're in a cloned repository or run 'git init' to create an empty Git repository and reinstall husky.

the .git is in the dockerignore . i also tried to remove it from there

how can I fix it ?

I think the way install git will help. But husky requiring git when build feels not necessary. Add more info here in case it helps.

I just got same error after updating husky from 4.3.0 to 4.3.4. It happens both when I try to build in Heroku, and also in the docker.

error /app/node_modules/husky: Command failed.
Exit code: 1
Command: node husky install
Arguments:
Directory: /app/node_modules/husky
Output:
husky > Setting up git hooks
Cannot read property 'toString' of null
husky > Failed to install

Hi @typicode

It might happen because I don’t have git installed in some of the Docker images that my CI uses. node:10-slim for instance. So if the git version check is part of husky, maybe do it after checking if husky should be installed at all (isCI).

@typicode

With 4.3.8 I’m get ting git --version command failed. Got null instead.

Hi @typicode

This issue seems to have been around for quite some time, but has lately received some traction. Do you have a comment on how to fix this?

Best regards Jens

Indeed, I also revert back to husky@4.3.0 while waiting for a fix.