dethcrypto / TypeChain

🔌 TypeScript bindings for Ethereum smart contracts
MIT License
2.76k stars 365 forks source link

Error: Couldn't find ethers-v5 (yarn workspaces) #620

Open smartcontracts opened 2 years ago

smartcontracts commented 2 years ago

I'm getting the following error on the latest version of typechain:

Error: Couldn't find ethers-v5. Tried loading: @typechain/ethers-v5, typechain-target-ethers-v5, /home/k/Projects/work/optimism/packages/contracts/ethers-v5.
Perhaps you forgot to install @typechain/ethers-v5?

This is happening within a yarn/lerna monorepo. It appears this is happening because the typechain package is being hoisted to the root level, but the @typechain/ethers-v5 package is not.

aspiers commented 2 years ago

I had this too. It went away when I bumped typechain from 5.2.0 to 7.0.0 but that was probably just luck.

aspiers commented 2 years ago

Turns out it was just luck indeed. The issue randomly reappeared later even after upgrading to 7.0.0. After much trial and error, the only thing which fixed it for me was:

"nohoist": [
  "**/typechain",
  "**/@typechain/*"
]
krzkaczor commented 2 years ago

@smartcontracts does @aspiers fix work for you? yarn monorepos can be a mess...

smartcontracts commented 2 years ago

I'll give this fix a shot tomorrow and report back to you!

krzkaczor commented 2 years ago

@smartcontracts let me know. Also if you have a PR that I can look at that it could make debugging easier.

My bet would be that yarn decided to spread dependencies into a different tree after the upgrade and that's why it doesn't work now (note that waffle has a dependency on the old typechain version which make also affect your case).

hasparus commented 2 years ago

Just FYI, I've made target resolution more robust in the new version, so this should (no guarantees) be solved after the release.