由于节点应用程序中的 Husky 故障而无法提交

发布于 2025-01-13 00:05:28 字数 1801 浏览 4 评论 0原文

我创建了一个节点应用程序并安装了 Husky7.0.4 和 lint-staged12.3.5

以下是配置 .husky/pre-commit --- 文件

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run pre-commit

和以下是 package.json 配置

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "nodemon --exec babel-node index.js",
    "build": "rimraf dist/ && babel ./ --out-dir dist/ --ignore ./node_modules,./.babelrc,./package.json,./npm-debug.log --copy-files",
    "prettier:check": "prettier --check .",
    "prettier:fix": "prettier --write .",
    "lint:check": "eslint .",
    "lint:fix": "eslint --fix .",
    "pre-commit": "lint-staged",
    "prepare": "husky install"
  },
  "lint-staged": {
    "*.js": [
      "lint:check",
      "lint:fix",
      "prettier:fix"
    ]
  },
  "dependencies": {
    "lint-staged": "^12.3.5",
  },
  "devDependencies": {
    "@babel/cli": "^7.17.6",
    "@babel/core": "^7.17.5",
    "@babel/node": "^7.16.8",
    "@babel/preset-env": "^7.16.11",
    "eslint": "^8.10.0",
    "eslint-config-prettier": "^8.5.0",
    "husky": "^7.0.4",
    "nodemon": "^2.0.15",
    "prettier": "^2.5.1"
  } 

但是每次提交代码时我都会收到以下错误

> [email protected] pre-commit
> lint-staged

✔ Preparing lint-staged...
⚠ Running tasks for staged files...
  ❯ package.json — 1 file
    ❯ *.js — 1 file
      ✖ lint:check [ENOENT]
      ◼ lint:fix
      ◼ prettier:fix
↓ Skipped because of errors from tasks. [SKIPPED]
✔ Reverting to original state because of errors...
✔ Cleaning up temporary files...

✖ lint:check failed without output (ENOENT).
husky - pre-commit hook exited with code 1 (error)  

I have created a node application and installed Husky7.0.4 and lint-staged12.3.5

following are the configuration for
.husky/pre-commit --- file

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run pre-commit

and following are the package.json config

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "nodemon --exec babel-node index.js",
    "build": "rimraf dist/ && babel ./ --out-dir dist/ --ignore ./node_modules,./.babelrc,./package.json,./npm-debug.log --copy-files",
    "prettier:check": "prettier --check .",
    "prettier:fix": "prettier --write .",
    "lint:check": "eslint .",
    "lint:fix": "eslint --fix .",
    "pre-commit": "lint-staged",
    "prepare": "husky install"
  },
  "lint-staged": {
    "*.js": [
      "lint:check",
      "lint:fix",
      "prettier:fix"
    ]
  },
  "dependencies": {
    "lint-staged": "^12.3.5",
  },
  "devDependencies": {
    "@babel/cli": "^7.17.6",
    "@babel/core": "^7.17.5",
    "@babel/node": "^7.16.8",
    "@babel/preset-env": "^7.16.11",
    "eslint": "^8.10.0",
    "eslint-config-prettier": "^8.5.0",
    "husky": "^7.0.4",
    "nodemon": "^2.0.15",
    "prettier": "^2.5.1"
  } 

But I am getting the following error every time I am committing my code

> [email protected] pre-commit
> lint-staged

✔ Preparing lint-staged...
⚠ Running tasks for staged files...
  ❯ package.json — 1 file
    ❯ *.js — 1 file
      ✖ lint:check [ENOENT]
      ◼ lint:fix
      ◼ prettier:fix
↓ Skipped because of errors from tasks. [SKIPPED]
✔ Reverting to original state because of errors...
✔ Cleaning up temporary files...

✖ lint:check failed without output (ENOENT).
husky - pre-commit hook exited with code 1 (error)  

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

软糯酥胸 2025-01-20 00:05:28

我可以通过将 lint-stage 中的任务从 更改为 来解决此

"lint-staged": {  
  "*.js": [ 
      "lint:check", 
      "lint:fix", 
      "prettier:fix" 
  ] 
 } 

问题

"lint-staged": { 
  "*.js": [ 
    "npm run lint:check", 
    "npm run lint:fix", 
    "npm run prettier:fix" 
   ] 
 }

I am able to fix the issue by changing the tasks in lint-stage from

"lint-staged": {  
  "*.js": [ 
      "lint:check", 
      "lint:fix", 
      "prettier:fix" 
  ] 
 } 

to

"lint-staged": { 
  "*.js": [ 
    "npm run lint:check", 
    "npm run lint:fix", 
    "npm run prettier:fix" 
   ] 
 }
影子的影子 2025-01-20 00:05:28

我可以通过更改来解决问题

"lint-staged": {
    "*.{js,jsx,ts,tsx}": [
      "yarn lint:fix",
      "yarn prettier:check",
      
      "git add"
    ]
  },

I am able to fix the issue by changing

"lint-staged": {
    "*.{js,jsx,ts,tsx}": [
      "yarn lint:fix",
      "yarn prettier:check",
      
      "git add"
    ]
  },
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文