Reputation: 58
I have set up a husky hook for a react app, for eslint and prettier, though when I commit and the prettier script runs I get this error:
> eslint --fix src/**/*.js
> prettier src/**/*.js --write. --config ./.prettierrc
[error] Cannot read property '' of null
> husky - pre-commit hook exited with code 1 (error)
I have checked the entire app for this '' null condition though have found nothing.
.prettierrc
{
"arrowParens": "always",
"bracketSpacing": true,
"embeddedLanguageFormatting": "auto",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxSingleQuote": false,
"proseWrap": "preserve",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": true,
"singleQuote": false,
"trailingComma": "es5",
"useTabs": false,
"vueIndentScriptAndStyle": false,
"printWidth": 150,
"tabWidth": 4,
"rangeStart": 0
}
package.json
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"lint": "eslint --fix src/**/*.js",
"format": "prettier src/**/*.js --write. --config ./.prettierrc",
"prepare": "husky install"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"husky": {
"hooks": {
"pre-commit": "npm run lint && npm run format"
}
},
"devDependencies": {
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.27.1",
"eslint-plugin-react-hooks": "^4.3.0",
"husky": "^7.0.4",
"prettier": "^2.5.1"
}
Upvotes: 0
Views: 1100
Reputation: 1
There is typo in format script, you can just put it as
"format": "prettier src/**/*.js --write"
Upvotes: 0