使用 npm test && np --no-cleanup --yolo --no-publish --any-branch 发布代码时报错误
? Select semver increment or specify new version patch 0.0.10✔ Git✖ Bumping version using npm→ v0.0.10Pushing tags✖ Command failed with exit code 1: npm version 0.0.10npm ERR! code 1npm ERR! Command failed: git commit -m 0.0.10npm ERR! nvm is not compatible with the "npm_config_prefix" environment variable: currently set to "/Users/xxx/.nvm/versions/node/v14.17.6"npm ERR! Run `unset npm_config_prefix` to unset it.npm ERR! > running pre-commit hook: lint-staged && npm run lintnpm ERR! lint-staged requires at least version 12.13.0 of Node, please upgradenpm ERR!npm ERR! pre-commit hook failed (add --no-verify to bypass)npm ERR!npm ERR! A complete log of this run can be found in:npm ERR! /Users/xxx/.npm/_logs/2021-09-29T11_30_41_453Z-debug.logv0.0.10npm ERR! code ELIFECYCLEnpm ERR! errno 1
解决方案,
执行 unset npm_config_prefix 这个没效果
通过参考实践以下的文档,尝试了使用各个方案暂时没效果
- 方案一:想通过修改 np 代码,在执行 npm version patch 时添加 —no-verify 参数,执行仍然报错
- const args = [‘version’, input, ‘—no-verify’]; // 新增参数
- pre-commit hook failed (add —no-verify to bypass)
- 方案二:想通过添加 lint-staged 的 ignore 配置来处理,结果 ignore参数已经废弃
- “lint-staged”: {
“*.{js,jsx,less,md,json}”: [
“prettier —write”
],
“ignore”: [“node_modules”, “dist”, “package-lock.json”, “package.json”]
},
经过查询文档,lint-staged 使用 yorkie 来实现 git hooks的钩子 pre-commit,而 yorkie 是 husky 的 fork,已有三年未更新了,所以决定改为 husky 方案实现 git 的钩子
文档 husky
以下方法也许可以 HUSKY=0 git push # yolo!
安装
npx husky-init && npm installnpm set-script prepare "husky install"// 添加 scripts "prepare": "husky install"// 添加钩子npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'npx husky add .husky/pre-commit "npm test"
参考:
