Handle correctly all the popular package managers
At the moment, Hardhat works pretty well with npm 7 or later, but it's not great for other package managers, especially when the Toolbox is involved:
- Older versions of npm and yarn v1 don't auto-install peer dependencies, so every package has to be manually installed.
- pnpm and the new yarn can auto install peer deps, but this is an opt-in behavior. AFAIK, this can be done via a a configuration file or a command line flag.
In addition to this, our docs don't correctly reflect the fact that there are two yarns out there, nor they include pnpm. Maybe we can add a new tab for yarn berry and pnpm, or maybe there's another way to do this.
In any case, this is a tracking issue to, at least:
- Make sure the project initialization correctly handles the different package managers. #3554 was a first step in that direction.
- Improve the docs to better explain and reflect the fact that there are multiple package managers
- If possible, improve errors related to missing peer dependencies to point the users in the right direction. Maybe having a central guide about this is necessary.
Does Hardhat support Pnpm's flat node_modules layout (which puts peer dependencies in the virtual directory node_modules/.pnpm?
Even with auto-install-peers enabled, I cannot get Hardhat to compile code from an npm package (@sablier/v2-core) that itself has a dependency and peer dependency on another npm package (@openzeppelin/contracts). I am getting this error:
Error HH411: The library @openzeppelin/contracts, imported from @sablier/v2-core/src/types/Tokens.sol, is not installed. Try installing it using npm.
This is even if OpenZeppelin is listed both as a dependency and as a peer dependency in Sablier.
The problem seems to be that Hardhat does not look for dependencies in Pnpm's virtual store in node_modules/.pnpm. I put together a repro on the pnpm-sablier-deps branch in my Hardhat template.
I can confirm that this bug occurs only with Pnpm. I spun up a Hardhat project using the configuration wizard, installed @sablier/v2-core using npm (instead of pnpm), and then I was able to compile the OpenZeppelin code.
Repro: https://github.com/PaulRBerg/hardhat-pnpm-sablier
Thanks Paul, I noticed the same thing when looking into #4194. I opened https://github.com/NomicFoundation/hardhat/issues/4292 to track this specific issue.
Is there any updates or roadmap on that @fvictorio? I can confirm I am experiencing the same. We have moved to a monorepo (using Turborepo) with lukso-network/lsp-smart-contracts and I am encountering the same error message as @PaulRBerg
Even with the following pnpm configurations in .npmrc.
auto-install-peers=true
link-workspace-packages=deep
prefer-workspace-packages=true
I would love to know when this is planned to be fixed.
This will require internal reworking our import resolution code, this is something we will take a look at for our next major version.