Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postinstall isn't executing in npm@7 #776

Closed
EduSantosBrito opened this issue Oct 16, 2020 · 20 comments
Closed

postinstall isn't executing in npm@7 #776

EduSantosBrito opened this issue Oct 16, 2020 · 20 comments

Comments

@EduSantosBrito
Copy link

Node: v14.14.0
Npm: 7.0.1

My package.json:

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "dist/index.js",
  "husky": {
    "hooks": {
      "pre-commit": "echo 'foo'"
    }
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "license": "ISC",
  "devDependencies": {
    "husky": "^4.3.0"
  }
}

When I execute npm i or npm i -D husky the postinstall script does not execute.

@maninak
Copy link

maninak commented Oct 19, 2020

Same here. Running git commit results in:

could not determine executable to run

image

@maninak
Copy link

maninak commented Oct 19, 2020

Downgrading npm fixed it for me (for now, as a work-around).

npm install npm@latest -g
npm -v # 6.14.8

@mmiszy
Copy link

mmiszy commented Oct 23, 2020

Same problem on npm@7.0.3.

Solved it by migrating to husky@5 (beta)

@chimericdream
Copy link

I am running into this as well, except updating to the beta version is not working in my case. This is on Node 14 and 15 with npm 7.

@mmiszy
Copy link

mmiszy commented Oct 26, 2020

@chimericdream make sure you read the Readme for husky@5 because they changed the setup.

@chimericdream
Copy link

chimericdream commented Oct 26, 2020

@mmiszy so it seems! Good old user error in this case. Updating to v5 and following the instructions did the trick for me. Thank you!

@exbotanical
Copy link

I can likewise verify that anyone finding themselves here will need to follow the v5 docs carefully; you can't be as liberal with setting up the hooks as you might have been using prior versions.

@MiguelMachado-dev
Copy link

Downgrading npm fixed it for me too, thanks @maninak
Seems to be something with npm@7

@exbotanical
Copy link

Coming back to this issue, I wanted to do some work on a package and ran a fresh npm install on my new machine. Quickly discovered that while the commit-msg hook installs, Husky cannot resolve the path to commitlint. If I point it at the binary in my node modules, the Husky environment variables aren't extant when the hook executes. I was able to get this to work by piping the commit message through a shell script but at this point it was diminishing returns.

This was with npm@7, husky@5.0.0-beta.0. Downgraded back to husky@4.3.0 with npm@7 and everything is working again.

@shian15810
Copy link

Should be related to this issue: npm/cli#1905

@d-fischer
Copy link

I tracked it down to being caused by INIT_CWD being missing in npm 7: npm/cli#2033

@typicode
Copy link
Owner

typicode commented Dec 5, 2020

Exactly, as a workaround, INIT_CWD could be manually set:

INIT_CWD="$(pwd)" npm install husky --save-dev

I've v4 docs and release a new version that should make it clearer.

voxpelli added a commit to voxpelli/async-htm-to-string that referenced this issue Dec 6, 2020
Avoids Husky not working with NPM 7 which is included in Node 15: typicode/husky#776
@jameschensmith
Copy link

This should be resolved now in npm v7.1.2. I've run some tests locally using npm i and npm ci, and hooks were installed with both.

@typicode
Copy link
Owner

typicode commented Jan 7, 2021

Thanks for confirming it :) @jameschensmith

@almothafar
Copy link

I got the issue even with npm 7.5.x

Personally, I was able to fix my issue by removing hooks folder inside .git, and then reinstall husky

npm uninstall husky
npm install husky --save-dev

@omonk
Copy link

omonk commented Feb 10, 2021

Still getting errors after uninstalling and reinstalling with npm -v 7.5.3.

No post install scripts seem to npm and

▲  git commit 
npm ERR! could not determine executable to run

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/ollie/.npm/_logs/2021-02-10T12_45_49_014Z-debug.log

npm debug log:

0 verbose cli [
0 verbose cli   '/usr/local/Cellar/node/15.8.0/bin/node',
0 verbose cli   '/usr/local/lib/node_modules/npm/bin/npm-cli.js',
0 verbose cli   'exec',
0 verbose cli   '--yes=false',
0 verbose cli   '--',
0 verbose cli   'husky-run',
0 verbose cli   'pre-commit',
0 verbose cli   ''
0 verbose cli ]
1 info using npm@7.5.3
2 info using node@v15.8.0
3 timing config:load:defaults Completed in 1ms
4 timing config:load:file:/usr/local/lib/node_modules/npm/npmrc Completed in 1ms
5 timing config:load:builtin Completed in 1ms
6 timing config:load:cli Completed in 2ms
7 timing config:load:env Completed in 0ms
8 timing config:load:file:/Users/ollie/path/to/project/.npmrc Completed in 0ms
9 timing config:load:project Completed in 1ms
10 timing config:load:file:/Users/ollie/.npmrc Completed in 0ms
11 timing config:load:user Completed in 0ms
12 timing config:load:file:/usr/local/etc/npmrc Completed in 1ms
13 timing config:load:global Completed in 1ms
14 timing config:load:cafile Completed in 0ms
15 timing config:load:validate Completed in 0ms
16 timing config:load:setUserAgent Completed in 0ms
17 timing config:load:setEnvs Completed in 1ms
18 timing config:load Completed in 7ms
19 verbose npm-session 925423bba9b1c886
20 timing npm:load Completed in 12ms
21 http fetch GET 304 https://registry.npmjs.org/husky-run 113ms (from cache)
22 timing command:exec Completed in 121ms
23 verbose stack Error: could not determine executable to run
23 verbose stack     at getBinFromManifest (/usr/local/lib/node_modules/npm/lib/exec.js:272:23)
23 verbose stack     at exec (/usr/local/lib/node_modules/npm/lib/exec.js:182:15)
24 verbose cwd /Users/ollie/sites/petsapp/frontend
25 verbose Darwin 19.6.0
26 verbose argv "/usr/local/Cellar/node/15.8.0/bin/node" "/usr/local/lib/node_modules/npm/bin/npm-cli.js" "exec" "--yes=false" "--" "husky-run" "pre-commit" ""
27 verbose node v15.8.0
28 verbose npm  v7.5.3
29 error could not determine executable to run
30 verbose exit 1

@almothafar
Copy link

almothafar commented Feb 11, 2021

@omonk for me reinstalling worked fine, but the next day I got the same issue again, to be honest, I didn't try again same steps as I gave up, reinstalling should be including "remove the hooks folder" if you missed it, reinstalling alone did not work for me, I did reinstall to recreate hooks folder again after I deleted it.

Now I removed the husky itself from my project until these issues got fixed.

@typicode
Copy link
Owner

Since this issue was created, husky 5 has been released so npm install husky now installs v5 instead of v4.
v5 works quite differently from v4 (see docs for new install instructions), so if you're using v5, I'd suggest creating a new issue as the cause may be different.

@mysterycommand
Copy link

I'm not sure if it belongs in a new issue or if this should be reopened, but I ran into an issue where I can't use Husky 5 (it's a for a closed-source project and I am not in control of our GitHub budget). I first ran npm install --save-dev husky and then had to npm uninstall husky && npm install --save-dev husky@4.

The issue I ran into is that Husky 5 (as part of it’s install/postinstall) does the equivalent of git config set core.hooksPath .husky but doesn’t clean that up in it’s preuninstall script, so installing Husky 4 after Husky 5 requires running git config --unset core.hooksPath. Otherwise Git is looking for hooks in a folder that doesn't exist.

Anyway, leaving this here in case it helps someone else.

@netpoe
Copy link

netpoe commented Apr 7, 2021

I'm not sure if it belongs in a new issue or if this should be reopened, but I ran into an issue where I can't use Husky 5 (it's a for a closed-source project and I am not in control of our GitHub budget). I first ran npm install --save-dev husky and then had to npm uninstall husky && npm install --save-dev husky@4.

The issue I ran into is that Husky 5 (as part of it’s install/postinstall) does the equivalent of git config set core.hooksPath .husky but doesn’t clean that up in it’s preuninstall script, so installing Husky 4 after Husky 5 requires running git config --unset core.hooksPath. Otherwise Git is looking for hooks in a folder that doesn't exist.

Anyway, leaving this here in case it helps someone else.

For the record, git config set core.hooksPath .husky will throw an error at git version 2.24.3 (Apple Git-128).
So git config --add core.hooksPath .husky worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests