Why paths specified on the CLI are not relative to `--base-path`?
See original GitHub issuei am unclear on what ‘root of source tree’ means when using the base-path
flag
$(npm bin)/solcjs --bin --output-dir build --base-path ./contracts Test.sol
returns : Error reading Test.sol: Error: ENOENT: no such file or directory, open 'Test.sol'
$(npm bin)/solcjs --bin --output-dir build --base-path . contracts/Test.sol
works and compiles contract
Issue Analytics
- State:
- Created a year ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Avoiding relative paths in Angular CLI - Stack Overflow
paths tsconfig option is relative to baseUrl option (so keep in mind and use relative paths for the paths keys). * - the...
Read more >Import Path Resolution — Solidity 0.8.16 documentation
The working directory of the compiler is one of the paths allowed by default only if it happens to be the base path...
Read more >Search path for libraries (path spec v3) · Issue #11409 - GitHub
By default base path is empty, which means that relative paths are relative to the current working directory while absolute paths remain ...
Read more >File path formats on Windows systems | Microsoft Learn
These "drive relative" paths are a common source of program and script logic errors.
Read more >Relative and absolute paths, in the file system and on the web ...
So it goes for the paths in the computer world: given the absolute address, you can always get to the place, no matter...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You can find detailed docs about how path resolution works in Import Path Resolution.
In short, the main purpose of base path is to be the location that direct imports are resolved against. I.e. if the base path is
/some/path/
, and you haveimport "a/b/c.sol"
in your contract, the compiler will look for the file in/some/path/a/b/c.sol
on disk.Base path is not the same thing as your working directory even though by default they have the same value. When they’re different, on the command-line it’s the working directory that counts:
In the above
a/b/c.sol
refers to/some/other/path/a/b/c.sol
because that’s how everyone expects relative paths to work on the CLI. It does not magically become/some/path/a/b/c.sol
Why not. Feel free to submit a PR to adjust that. We could add a sentence or two on that and maybe link to specific bits in the import path resolution docs. Like, the
--base-path
option could be a link to the section on base path and we could also link to https://docs.soliditylang.org/en/latest/path-resolution.html#cli-path-normalization-and-stripping.