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

Husky 3.0.3 not working with yarn pnp [Mac] #560

Closed
csi-lk opened this issue Aug 13, 2019 · 10 comments
Closed

Husky 3.0.3 not working with yarn pnp [Mac] #560

csi-lk opened this issue Aug 13, 2019 · 10 comments

Comments

@csi-lk
Copy link

csi-lk commented Aug 13, 2019

Could be related to: #553

Am using yarn PnP and tried to follow @arcanis' PR #511 to use
yarn husky-run / HUSKY_USE_YARN=1

Can't tell if there's something wrong in my implementation:

(doesn't seem to matter what's in the .huskyrc.js file)

$ yarn remove husky && yarn add husky@3.0.3 --dev
$ yarn husky-run
yarn run v1.16.0
error Command "husky-run" not found.
$ git commit -m "test"
Error: Cannot find module 'please-upgrade-node'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/Users/callumsilcock/dev/js-modules.library/.pnp/unplugged/npm-husky-3.0.3-6f3fb99f60ef72cdf34e5d78445c2f798c441b1d/node_modules/husky/run.js:3:27)
[...]
$ HUSKY_USE_YARN=1 git commit -m "test"
yarn run v1.16.0
error Command "husky-run" not found
@arcanis
Copy link
Contributor

arcanis commented Aug 13, 2019

Yarn v1 seems to have some problems with running PnP binaries which are unplugged (which Husky has to be because of how it uses the postinstall hook to copies itself into .git) 🤔

I would recommend to use Yarn v2 if you're already looking to use PnP, as its implementation is generally more mature there (although the v2 is still technically in developer preview). Here's an example of what it would look like (note that HUSKY_USE_YARN is required at the end to get rid of the run-node: not a directory error):

❯ [COMP11310.local?] husky-test/tmp/husky-test git:(master) ❯ yarn init -y

yarn init v1.17.2
warning The yes flag has been set. This will automatically answer yes to all questions, which may have security implications.
success Saved package.json
Done in 0.04s.                                                                                                                                                                                          

❯ [COMP11310.local?] husky-test/tmp/husky-test git:(master) ✗ ❯ yarn policies set-version v2

Resolving v2 to a url...
Downloading https://github.com/yarnpkg/berry/raw/master/packages/berry-cli/bin/berry.js...
Saving it into /private/tmp/husky-test/.yarn/releases/yarn-berry.js...
Updating /private/tmp/husky-test/.yarnrc...
Done!

❯ [COMP11310.local?] husky-test/tmp/husky-test git:(master) ✗ ❯ yarn add husky@3.0.3 --dev

➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed in 1.65s
➤ YN0000: ┌ Fetch step
➤ YN0013: │ ...
➤ YN0000: └ Completed in 1.32s
➤ YN0000: ┌ Link step
➤ YN0007: │ husky@npm:3.0.3 must be built because it never did before or the last one failed
➤ YN0000: └ Completed in 0.47s
➤ YN0000: Done in 3.45s

❯ [COMP11310.local?] husky-test/tmp/husky-test git:(master) ✗ ❯ git commit --allow-empty -m 'foo'

.git/hooks/pre-commit: line 47: .yarn/cache/run-node-npm-1.0.0-dafcebdccb.zip/node_modules/run-node/run-node: Not a directory

❯ [COMP11310.local?] husky-test/tmp/husky-test git:(master) ✗ ❯ HUSKY_USE_YARN=1 git commit --allow-empty -m foo

[master (root-commit) 0ceb6b6] foo

@typicode
Copy link
Owner

I've published a new version, which is a very early v4.0.0 version. It should support Yarn PnP out of the box.

You can give it a try using yarn add husky@next --dev.

Feedback is welcome.

@csi-lk
Copy link
Author

csi-lk commented Aug 14, 2019

Hey @typicode , 4.0.0-beta.0 doesn't seem to be working on older yarn 1.17.3:

$ yarn add husky@next --dev
[...]
success Saved 1 new dependency.
info Direct dependencies
└─ husky@4.0.0-beta.0
info All dependencies
└─ husky@4.0.0-beta.0
✨  Done in 10.10s.

$ HUSKY_USE_YARN=1 git add -A && git commit --amend

yarn install v1.17.3
error `install` has been replaced with `add` to add new dependencies. Run "yarn add husky-run pre-commit " instead.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

@arcanis
Copy link
Contributor

arcanis commented Aug 14, 2019

Will be fixed by #562 🙂

@csi-lk
Copy link
Author

csi-lk commented Aug 14, 2019

Can confirm @arcanis

yarn add arcanis/husky#mael/argv-fix

Seems to fix the running issue, but the hooks themselves are not executing, i'll have a look into why now

@typicode
Copy link
Owner

#562 was merged and husky v4.0.0-beta.1 was published

@ArnaudWeyts
Copy link

This issue isn't fixed for me on v4.0.0-beta-1 🤔

I removed all the hooks, reinstalled the newest version and it's still giving me a
error Command "husky-run" not found.

I'm on yarn v1.17.3

@plumpNation
Copy link

plumpNation commented Jan 30, 2020

I get this error when I rm the node_modules and yarn install again. It is also ignored by --no-verify, which leaves the user without the ability to commit at all.

yarn 1.21.1
husky 4.2.1

@virtuoushub
Copy link

In case this helps anyone, I was running into this issue and was able to work around it.

Solved via:

yarn add -D zen-observable

➜  bar git:(master) ✗ yarn --version
2.0.0-rc.27
➜  bar git:(master) ✗ cat package.json | grep husky
    "husky": "^4.2.1",

Used #560 (comment) to help me debug.

➜  bar git:(master) ✗ HUSKY_USE_YARN=1 git add -A && git commit --amend
husky > pre-commit (node v12.14.0)
/foo/bar/.yarn/cache/any-observable-npm-0.3.0-4832f4f3ed-1.zip/node_modules/any-observable/register.js:29
		throw new Error('Cannot find any-observable implementation nor' +
		^

Error: Cannot find any-observable implementation nor global.Observable. You must install polyfill or call require("any-observable/register") with your preferred implementation, e.g. require("any-observable/register")('rxjs') on application load prior to any require("any-observable").
    at loadImplementation (/foo/bar/.yarn/cache/any-observable-npm-0.3.0-4832f4f3ed-1.zip/node_modules/any-observable/register.js:29:9)
    at /foo/bar/.yarn/cache/any-observable-npm-0.3.0-4832f4f3ed-1.zip/node_modules/any-observable/loader.js:30:18
    at Object.<anonymous> (/foo/bar/.yarn/cache/any-observable-npm-0.3.0-4832f4f3ed-1.zip/node_modules/any-observable/index.js:2:39)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.module_1.Module._load (/foo/bar/.pnp.js:21489:14)
    at Module.require (internal/modules/cjs/loader.js:852:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/foo/bar/.yarn/cache/@samverschueren-stream-to-observable-npm-0.3.0-3da2ac7de0-1.zip/node_modules/@samverschueren/stream-to-observable/index.js:2:20)

@dsturm
Copy link

dsturm commented Mar 6, 2020

@virtuoushub Thanks for your hint, works for me.

This issue was closed.
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

7 participants