Closed icrm-af closed 3 years ago
Thank you for filing this issue. We appreciate your feedback and will review the issue as soon as possible. Remember, however, that GitHub isn't a mechanism for receiving support under any agreement or SLA. If you require immediate assistance, contact Salesforce Customer Support.
did you add husky or did it come from project:create
? What's in .husky folder or .huskyrc.js?
When was the project created?
a quick solution would be to run force:project:create
somewhere else and then move over the .husky
directory that it creates to this project
I just tested this:
Created the project using sfdx:project:create
, initialized a github repo using git init
, created git repo using gh repo create
, added files using git add .
, committed changes via git commit -m "<MSG>"
, it worked fine, then I ran npm install
, made some changes and repeated the process to commit and it errored.
@mshanemc
I can't get the error to appear.
Does the error reproduce for you only if you gh repo create
or is that step irrelevant?
Hi @icrm-af, let's try to reproduce the issue with the simplest scenario. Can you run these commands:
sfdx force:project:create -n test
cd test
git init
npm install
git commit -a -m "Initial commit"
In order to figure out what's wrong, we need to see the output of all of these commands. Can you save them and share them here?
Log for:
sfdx force:project:create -n test
{
"status": 0,
"result": {
"outputDir": "C:\\Users\\myUser\\Desktop\\VSCode Projects",
"created": [
"test\\config\\project-scratch-def.json",
"test\\README.md",
"test\\sfdx-project.json",
"test\\.husky\\pre-commit",
"test\\.vscode\\extensions.json",
"test\\.vscode\\launch.json",
"test\\.vscode\\settings.json",
"test\\force-app\\main\\default\\lwc\\.eslintrc.json",
"test\\force-app\\main\\default\\aura\\.eslintrc.json",
"test\\scripts\\soql\\account.soql",
"test\\scripts\\apex\\hello.apex",
"test\\.eslintignore",
"test\\.forceignore",
"test\\.gitignore",
"test\\.prettierignore",
"test\\.prettierrc",
"test\\jest.config.js",
"test\\package.json"
],
"rawOutput": "target dir = C:\\Users\\myUser\\Desktop\\VSCode Projects\n create test\\config\\project-scratch-def.json\n create test\\README.md\n create test\\sfdx-project.json\n create test\\.husky\\pre-commit\n create test\\.vscode\\extensions.json\n create test\\.vscode\\launch.json\n create test\\.vscode\\settings.json\n create test\\force-app\\main\\default\\lwc\\.eslintrc.json\n create test\\force-app\\main\\default\\aura\\.eslintrc.json\n create test\\scripts\\soql\\account.soql\n create test\\scripts\\apex\\hello.apex\n create test\\.eslintignore\n create test\\.forceignore\n create test\\.gitignore\n create test\\.prettierignore\n create test\\.prettierrc\n create test\\jest.config.js\n create test\\package.json\n"
}
}
Log for:
git init
Initialized empty Git repository in C:/Users/myUser/Desktop/VSCode Projects/test/.git/
Log for:
npm install
`
core-js@3.16.1 postinstall C:\Users\myUser\Desktop\VSCode Projects\test\node_modules\core-js node -e "try{require('./postinstall')}catch(e){}"
[96mThank you for using core-js ([94m https://github.com/zloirock/core-js [96m) for polyfilling JavaScript standard library![0m
[96mThe project needs your help! Please consider supporting of core-js:[0m [96m>[94m https://opencollective.com/core-js [0m [96m>[94m https://patreon.com/zloirock [0m [96m>[94m https://paypal.me/zloirock [0m [96m>[94m bitcoin: bc1qlea7544qtsmj2rayg0lthvza9fau63ux0fstcz [0m
[96mAlso, the author of core-js ([94m https://github.com/zloirock [96m) is looking for a good job -)[0m
salesforce-app@1.0.0 postinstall C:\Users\myUser\Desktop\VSCode Projects\test husky install
husky - Git hooks installed added 961 packages from 378 contributors and audited 963 packages in 866.328s
89 packages are looking for funding
run npm fund
for details
found 0 vulnerabilities
`
Output for git commit
:
git commit -a -m "Initial commit" >> git_commit_log.txt
error: cannot spawn .husky/pre-commit: No such file or directory
@pozil
I can't get the error to appear.
Does the error reproduce for you only if you
gh repo create
or is that step irrelevant?
That step is irrelevant.
I'll uninstall and install everything again.
I uninstalled Git, SFDX CLI, Node, Heroku, and many other tools, ran a cleanup, installed everything again, and the same issue, I know is related to my computer but I would like to find a way to fix this instead of living with it or reinstall my OS.
Thanks for sharing your logs @icrm-af, everything looks normal.
I saw that Husky updated it's commit hook template but I'm not sure if this has an impact.
Can you replace the content of .husky/pre-commit
with the following (the second line is new):
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npm run precommit
Once the file is updated, try to commit something to check if this fixes the pre-commit hook.
Thanks for sharing your logs @icrm-af, everything looks normal.
I saw that Husky updated it's commit hook template but I'm not sure if this has an impact. Can you replace the content of
.husky/pre-commit
with the following (the second line is new):#!/bin/sh . "$(dirname "$0")/_/husky.sh" npm run precommit
Once the file is updated, try to commit something to check if this fixes the pre-commit hook.
@pozil that worked.
But seems to be something wrong with my environment, because it doesn't fail in other instances.
Thanks for the update. I'm pushing this change to the new DX project template just in case.
My fix has been incorporated in the DX project template and should be available in the upcoming Salesforce CLI release.
@mshanemc we can close this issue.
@pozil issue came back, but now I'm on a different computer, clean OS.
After I do npm install on a fresh project and then try to commit changes, error: cannot spawn .husky/pre-commit: No such file or directory appears.
Damn :(
My proposed fix hasn't landed on the CLI GA branch yet so I'm wondering if there's something else to it.
Can you apply it manually (edit .husky/pre-commit
) and check if it helps?
I've tried creating a new project with sfdx force:project:create -n test-project
and can see pozil's patch locally in the husky folder.
I guess when @icrm-af tried last time sfdx was still using an older version of the template. Can you see if you are still seeing this issue with the latest version?
I'm using sfdx-cli/7.122.1 darwin-x64 node-v14.18.1
which includes templates 52.4.0 (core)
.
This issue has been automatically closed because there has been no response to our request for more information from the original author. Currently, there is not enough information provided for us to take action. Please reply and reopen this issue if you need additional assistance.
Summary
Getting error: cannot spawn .husky/pre-commit: No such file or directory when trying to commit, previously ran npm install. This started to happen when I upgraded to sfdx-cli/7.111.0.
Today I updated SFDX CLI but the error continues.
Steps To Reproduce:
Repository to reproduce: NotificationApp
npm install
git add .
git commit -m "Test this"
Expected result
Commit successfully with no errors.
Actual result
error: cannot spawn .husky/pre-commit: No such file or directory when trying to commit.
System Information
Additional information
package.json file