提交前钩子失败

4

我正在使用NestJs来开展我的新项目。

我正在使用以下命令添加所有文件:git add .

当我在添加完所有文件后进行提交时,husky会阻止提交并显示以下错误信息:

[文件路径]/.spec.ts'没有被包含在该项目中。

husky > pre-commit钩子失败(add --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"
    ]
  },

你是否正在运行 lint-staged 命令在 pre-commit 钩子中,并期望它们改变即将提交的内容? - bk2204
我使用了这个解决方案来解决我的问题 https://dev59.com/eFIG5IYBdhLWcg3wlCK8#63948896 - Sathiamoorthy
2个回答

3

0

你的 pre commit hook 失败是因为在你的 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"]
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接