簡體   English   中英

預提交掛鈎失敗

[英]Pre Commit Hook fails

我在我的新項目中使用NestJs

我正在使用此命令添加所有文件。 git add .

當我在添加所有文件后提交時,husky 會阻止提交並向我顯示此錯誤。

[文件路徑]/.spec.ts' 不包含在項目中。

husky > 預提交鈎子失敗(添加 --no-verify 繞過)

我隱式添加了該文件,但它仍然向我拋出該錯誤。

我的 tsconfig.json 文件

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": false,
    "noImplicitAny": false,
    "removeComments": true,
    "noLib": false,
    "allowSyntheticDefaultImports": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es6",
    "sourceMap": true,
    "allowJs": true,
    "outDir": "./dist",
    "baseUrl": "./src",
    "lib": ["dom", "es2018", "esnext"]
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules", "**/*.spec.ts"]
}

這就是我在 package.json 文件中添加 husky 命令的方式

 "scripts": {
    "lint": "tslint -p tsconfig.json -c tslint.json",
  },


"husky": {
    "hooks": {
      "pre-commit": "lint-staged",
      "post-commit": "git push origin HEAD"
    }
  },
  "lint-staged": {
    "*.ts": [
      "tslint -p tsconfig.json -c tslint.json",
      "git add"
    ]
  },

如果您使用的是 Windows 操作系統,那么將包含在您的 package.json 中的鈎子腳本應采用以下形式

 "husky": { "hooks": { "pre-push": "set CI=true&&npm test" } },

對於其他操作系統,請使用以下代碼段

 "husky": {
 "hooks": {
 "pre-push": "CI=true npm test"}},

更多信息: https : //facebook.github.io/create-react-app/docs/running-tests#on-your-own-environment

是否可能是因為您的 tsconfig.json 文件中的exclude屬性中有"**/*.spec.ts"作為值,所以您的預提交掛鈎失敗了?

你能不能像這樣編輯文件並測試它:

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": false,
    "noImplicitAny": false,
    "removeComments": true,
    "noLib": false,
    "allowSyntheticDefaultImports": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es6",
    "sourceMap": true,
    "allowJs": true,
    "outDir": "./dist",
    "baseUrl": "./src",
    "lib": ["dom", "es2018", "esnext"]
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules"]
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM