I followed the latest Husky docs, but I cannot see the pre-commit hook triggered for any commits.
My package.json
is updated after husky init
as below:
{
"name": "newswire-next",
"private": true,
"scripts": {
"dev": "NODE_OPTIONS='--inspect' next dev -p 3030",
"serve": "NODE_OPTIONS='--inspect' NEXT_PUBLIC_API_MOCKING=enabled next dev -p 3030",
"build": "next build",
"prod": "next build && next start -p 3030",
"start": "NODE_OPTIONS='-r dotenv/config newrelic' next start -p 3030",
"lint": "next lint --max-warnings=0",
"lint:fix": "next lint --fix",
"test": "jest",
"prepare": "husky"
},
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.5.2",
"@fortawesome/free-brands-svg-icons": "^6.5.2",
"@fortawesome/free-regular-svg-icons": "^6.5.2",
"@fortawesome/free-solid-svg-icons": "^6.5.2",
"@fortawesome/pro-duotone-svg-icons": "^6.5.2",
"@fortawesome/pro-light-svg-icons": "^6.5.2",
"@fortawesome/pro-regular-svg-icons": "^6.5.2",
"@fortawesome/pro-solid-svg-icons": "^6.5.2",
"@fortawesome/pro-thin-svg-icons": "^6.5.2",
"@fortawesome/react-fontawesome": "^0.2.2",
"@radix-ui/react-dialog": "1.0.5",
"@radix-ui/react-dropdown-menu": "2.0.6",
"@radix-ui/react-popover": "1.0.7",
"@radix-ui/react-select": "1.2.2",
"@radix-ui/react-tabs": "1.0.4",
"@radix-ui/react-tooltip": "1.0.7",
"@reduxjs/toolkit": "1.9.7",
"@zendeskgarden/css-bedrock": "^9.0.0",
"@zendeskgarden/react-accordions": "^8.54.1",
"@zendeskgarden/react-datepickers": "^8.54.0",
"@zendeskgarden/react-dropdowns": "^8.49.3",
"@zendeskgarden/react-grid": "^8.54.0",
"@zendeskgarden/react-tags": "^8.54.2",
"@zendeskgarden/react-theming": "^8.54.3",
"@zendeskgarden/svg-icons": "^6.30.2",
"axios": "^0.28.0",
"clsx": "1.2.1",
"date-fns": "^2.29.1",
"date-fns-tz": "2.0.1",
"dotenv": "^16.4.5",
"embla-carousel-react": "7.1.0",
"lodash.debounce": "4.0.8",
"newrelic": "11.19.0",
"next": "^14.2.15",
"next-redux-wrapper": "8.1.0",
"photoswipe": "5.4.4",
"pusher-js": "^7.4.0",
"react": "^18.3.1",
"react-circular-progressbar": "^2.1.0",
"react-dom": "^18.3.1",
"react-places-autocomplete": "^7.3.0",
"react-player": "^2.10.1",
"react-query": "^3.39.3",
"react-redux": "^8.1.3",
"react-remove-scroll": "2.5.10",
"react-social-media-embed": "^2.2.2",
"react-top-loading-bar": "^2.1.0",
"react-virtualized": "9.22.5",
"styled-components": "^4.4.1"
},
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.16.0",
"@babel/preset-env": "^7.16.4",
"@babel/preset-react": "^7.16.0",
"@next/eslint-plugin-next": "^12.3.4",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^16.0.0",
"@testing-library/react-hooks": "^7.0.2",
"@testing-library/user-event": "^14.5.2",
"@types/intercom-web": "2.8.26",
"@types/jest": "^27.5.2",
"@types/newrelic": "^9.14.3",
"@types/node": "16.11.68",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/react-virtualized": "^9.21.22",
"@typescript-eslint/eslint-plugin": "^4.30.0",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.2.4",
"babel-plugin-styled-components": "^1.13.2",
"cross-spawn": "7.0.6",
"css-loader": "^6.5.1",
"eslint": "7.32.0",
"eslint-config-next": "14.2.14",
"eslint-config-prettier": "^8.3.0",
"eslint-config-react-app": "^6.0.0",
"eslint-plugin-flowtype": "^5.10.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jest": "^24.7.0",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.27.1",
"eslint-plugin-react-hooks": "^4.3.0",
"eslint-plugin-simple-import-sort": "^7.0.0",
"eslint-plugin-testing-library": "^3.10.2",
"html-webpack-plugin": "^5.5.0",
"husky": "^9.1.7",
"identity-obj-proxy": "^3.0.0",
"ignore-loader": "^0.1.2",
"jest": "^27.5.1",
"jsdom": "^19.0.0",
"lint-staged": "^15.5.0",
"msw": "^0.36.3",
"next-router-mock": "0.9.13",
"postcss-loader": "^6.2.1",
"prettier": "^3.5.3",
"pusher-js-mock": "^0.3.8",
"react-cosmos": "^5.6.5",
"react-test-renderer": "^18.3.1",
"redux-mock-store": "^1.5.4",
"resize-observer-polyfill": "1.5.1",
"sass": "^1.50.1",
"sass-loader": "^12.4.0",
"style-loader": "^3.3.1",
"ts-jest": "^27.1.5",
"ts-loader": "^9.2.6",
"typescript": "^4.6.3",
"webpack": "^5.65.0",
"whatwg-fetch": "^3.6.2"
},
"overrides": {
"braces": "3.0.3",
"cross-spawn": "7.0.6",
"eslint": "7.32.0",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"msw": {
"workerDirectory": "public"
},
"engines": {
"npm": "8.x || 9.x || 10.x",
"node": "16.x || 18.x"
},
"lint-staged": {
"**/*": "prettier --write --ignore-unknown"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
I added lint-staged
to my package.json
:
"lint-staged": {
"**/*": "prettier --write --ignore-unknown"
},
In the .pre-commit
file:
npx lint-staged
Now when I make any changes and commits them, I don't see the pre-commit hook triggered at all:
libin@164 next % git commit -m "Husky 13th commit"
[add-husky-pre-commit-hooks 4b45c7dc1] Husky 13th commit
4 files changed, 12 insertions(+), 18 deletions(-)
libin@164 next %