Open SAPikachu opened 2 years ago
This also happens under certain circumstances (not yet entirely sure how to reproduce this reliably) when using pnpm
with symlinked node modules that host smart contracts (e.g. openzeppelin, etc.)
@fubhy About the foundry + pnpm issue (copying my answer from slack):
I've been investigating the symlink issue using the repo you shared (https://github.com/KedziaPawel/symlink-hardhat-bug). I've arrived to 2 conclusions:
Forge works on the provided settings because it uses the solc CLI instead of the json interface (which the extension uses).
I tried the following json inputs for solidity < 0.8.8 to try and make it work without success: Given import path is import '@openzeppelin/...' a) Set remappings to @openzeppelin => node_modules/@openzeppelin/ b) Set remappings to @openzeppelin => /absolute/path/to/node_modules/@openzeppelin/
Both give the "file outside allowed directories" error.
@SAPikachu I was able to reproduce the reported issue. Our extension does not behave as expected on hardhat project directories that are symlinked, because of the way we load the HRE for providing validation and other services (require.resolve
, which unavoidably resolves symlinks). We will have to think about possible workarounds for this.
This happens in fresh MUD projects too. Repro:
pnpm create mud@canary app
# selected vanilla, but i'm pretty sure it's not relevant
code app
And go to packages/contracts/src/systems/IncrementSystem.sol
. The @latticexyz/world/src/System.sol
import will show as not found.
@alcuadrado suggested we investigate the library: https://www.npmjs.com/package/resolve, and whether it can help us with out node require resolution for pnpm.
@kanej I wasn't able to crack it so far. These are my findings on the issue:
resolve
package helps bypassing the natural resolution of symlinks by node (have to be explicit with preserveSymlinks
option). Although this alone isn't enough to support symlinked projects.cwd
doesn't work for symlinked directories. Child process will be spawned with the cwd set to the resolved path.process.chdir()
will resolve the directory and the working directory will be set to the resolved path.cwd
from the worker processes, and replacing them with the variable passed down on child spawning (which contains the symlink). This, using resolve
, allows me to get the symlinked path to the hardhat module. But even though we require the files to get the HRE with the symlinked path, it seems that hardhat internally will resolve the symlink paths. Clues to this include that the directories exposed by the config (i.e. hre.config.paths.sources
), and the dependency graph built by hardhat itself, expose paths with the resolved directories.I'm sure there must be a simpler way of supporting symlinked directories. Perhaps we should look into how other language servers handle this.
Thanks @antico5, I'll take it from here :wave:
Any updates on this?
Any update on this?
No updates, we haven't progressed the investigation.
I use symlink to point my development workspace to a synced folder. When I open a hardhat project inside the symlink, I got following error and intellisense doesn't work correctly:
If I open the same project directly inside the real path without symlink, intellisense works correctly.
Environment:
VSCode (note that I use SSH remote extension to work with project inside a VM):
VM: