Skip to content

Instantly share code, notes, and snippets.

@amit08255
Last active February 23, 2022 12:00
Show Gist options
  • Save amit08255/8321c96b7de771e5d256e53cec07eee6 to your computer and use it in GitHub Desktop.
Save amit08255/8321c96b7de771e5d256e53cec07eee6 to your computer and use it in GitHub Desktop.
Husky hook not install fix

Fix Husky script not install issue

Run below commands:

npm install husky --save-dev
npx husky install
npm install lint-staged --save-dev
npx husky add .husky/pre-commit "node_modules/.bin/lint-staged && npm run test && npm run transpile && npm run build"

Another trick is to add postinstall install script which will always run after npm install.

Example package.json:

{
  "name": "nextjs-boilerplate",
  "version": "1.0.0",
  "description": "NextJS boilerplate to quick start with your project.",
  "main": "index.js",
  "scripts": {
    "postinstall": "del .husky /q && cd.. && npx husky uninstall && npx husky install ./Frontend/.husky && Frontend\\node_modules\\.bin\\husky add Frontend/.husky/pre-commit \"cd Frontend && npm run build\"",
    "transpile": "npx babel ./ --out-dir dist --ignore '/**/*.spec.js','/**/*.test.js','/**/*.jsx','./dist/','./node_modules/','./.next/','./__tests__/','./pages/','./jest.config.js'",
    "lint": "eslint . --ext .jsx,.js,.tsx,.ts",
    "lint-staged": "lint-staged",
    "dev": "next",
    "prebuild": "npm run lint-staged && npm run test",
    "build": "next build",
    "export": "next build && next export",
    "start": "next start",
    "test": "jest --coverage",
    "test:watch": "jest --watch",
    "test:debug": "node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand --watch",
    "validate": "npm run lint && npm run test"
  },
  "author": "Amit Kumar",
  "license": "ISC",
  "dependencies": {
    "@chakra-ui/react": "^1.7.4",
    "@emotion/react": "^11.7.1",
    "@emotion/styled": "^11.6.0",
    "@fontsource/lato": "^4.5.2",
    "ajv": "^8.10.0",
    "axios": "^0.24.0",
    "basicprimitives": "^6.5.1",
    "basicprimitivesreact": "^6.5.1",
    "formik": "^2.2.9",
    "framer-motion": "^5.6.0",
    "next": "^12.0.7",
    "prop-types": "^15.8.0",
    "react": "^17.0.2",
    "react-datepicker": "^4.6.0",
    "react-dnd": "^14.0.5",
    "react-dnd-html5-backend": "^14.1.0",
    "react-dom": "^17.0.2",
    "react-icons": "^4.3.1",
    "react-intl": "^5.24.1",
    "react-select": "^5.2.2",
    "react-table": "^7.7.0",
    "styled-components": "^5.3.3"
  },
  "devDependencies": {
    "@babel/cli": "^7.16.0",
    "@babel/core": "^7.16.5",
    "@babel/eslint-parser": "^7.16.5",
    "@babel/plugin-proposal-class-properties": "^7.16.5",
    "@babel/plugin-transform-regenerator": "^7.16.5",
    "@babel/plugin-transform-runtime": "^7.16.5",
    "@babel/preset-env": "^7.16.5",
    "@babel/preset-react": "^7.16.5",
    "@testing-library/dom": "^8.11.1",
    "@testing-library/jest-dom": "^5.16.1",
    "@testing-library/react": "^12.1.2",
    "@testing-library/user-event": "^13.5.0",
    "@types/jest": "^27.4.0",
    "@types/react": "^17.0.38",
    "@typescript-eslint/eslint-plugin": "^5.8.1",
    "@typescript-eslint/parser": "^5.8.1",
    "babel-eslint": "^10.1.0",
    "babel-jest": "^27.4.5",
    "babel-plugin-module-resolver": "^4.1.0",
    "babel-plugin-styled-components": "^2.0.2",
    "eslint": "^8.5.0",
    "eslint-config-airbnb": "^19.0.4",
    "eslint-import-resolver-babel-module": "^5.3.1",
    "eslint-plugin-import": "^2.25.3",
    "eslint-plugin-jest-dom": "^4.0.0",
    "eslint-plugin-jsx-a11y": "^6.5.1",
    "eslint-plugin-react": "^7.28.0",
    "eslint-plugin-react-hooks": "^4.3.0",
    "husky": "^7.0.4",
    "jest": "^27.4.5",
    "lint-staged": "^12.1.4",
    "postcss": "^8.4.5",
    "ts-jest": "^27.1.2",
    "typescript": "^4.5.4"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "airbnb"
    ]
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment