question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

compiler remappings fails if same name path

See original GitHub issue

Environment information

  • brownie Version: 1.12.1
  • ganache-cli Version: x.x.x
  • solc Version: x.x.x
  • Python Version: 2.7.17 or 3.6.9
  • OS: Ubuntu 18.04.5 LTS

What was wrong?

  1. forked ESD
  2. init new brownie dir
  3. moved contracts
  4. ESD uses truffle npm style imports so need to perform remappings
  5. install packages: brownie pm install OpenZeppelin/openzeppelin-contracts@2.5.1 brownie pm install uniswap/uniswap-v2-core@1.0.1 brownie pm install uniswap/uniswap-lib@2.1.0
  6. set remappings:
        remappings: 
            - "@openzeppelin=OpenZeppelin/openzeppelin-contracts@2.5.1"
            - "@uniswap/lib=uniswap/uniswap-lib@1.1.2"
            - "@uniswap/v2-core=uniswap/uniswap-v2-core@1.0.1"
  1. error on compile
contracts/oracle/Oracle.sol:21:1: ParserError: Source "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol" not found: File outside of allowed directories.
import '@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol';

If I flip the two uniswap remappings, the 2nd one always fails. eg)

        remappings: 
            - "@openzeppelin=OpenZeppelin/openzeppelin-contracts@2.5.1"
            - "@uniswap/v2-core=uniswap/uniswap-v2-core@1.0.1"
            - "@uniswap/lib=uniswap/uniswap-lib@1.1.2"

will produce errors

contracts/mock/MockUniswapV2PairTrade.sol:20:1: ParserError: Source "uniswap/uniswap-lib@1.1.2/contracts/libraries/FixedPoint.sol" not found: File not found.

How can it be fixed?

regex? it appears the remapping ignores the info after the / so uniswap/lib and uniswap/v2-core are just treated identically. the 2nd entry will always fail.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
utgardacommented, Jul 7, 2021

Totally reproducing:

compiler:
  solc:
    version: 0.8.3
    remappings:
      - "@openzeppelin-upgradeable=/home/username/.brownie/packages/OpenZeppelin/openzeppelin-contracts-upgradeable@4.1.0"
      - "@openzeppelin=OpenZeppelin/openzeppelin-contracts@4.1.0"

the above works, but if you remap as just

compiler:
  solc:
    version: 0.8.3
    remappings:
      - "@openzeppelin-upgradeable=OpenZeppelin/openzeppelin-contracts-upgradeable@4.1.0"
      - "@openzeppelin=OpenZeppelin/openzeppelin-contracts@4.1.0"

i.e. if 2 remappings have the same path prefix, it’s compiler errors “File not found” all over the place, like

ParserError: Source "OpenZeppelin/openzeppelin-contracts@4.1.0/contracts/access/Ownable.sol" not found: File not found.
2reactions
iamdefinitelyahumancommented, Dec 17, 2020

Thanks for the workaround, I’ll have a look here shortly.

For reference: https://docs.soliditylang.org/en/latest/using-the-compiler.html#path-remapping

Read more comments on GitHub >

github_iconTop Results From Across the Web

Import Path Resolution — Solidity 0.8.17 documentation
The compiler will only issue an error if the source unit name passed to the Host Filesystem Loader represents an existing path when...
Read more >
Compiling Contracts — Brownie 1.18.0 documentation
If one or more contracts are unable to compile, Brownie raises an exception with ... Brownie automatically ensures that all remapped paths are...
Read more >
Getting compiler error when trying to verify a contract ...
I've tried: Importing libraries with Brownie package manager; Importing libraries with npm and using relative paths; All kinds of different ...
Read more >
Documentation - Module Resolution - TypeScript
If that didn't work and if the module name is non-relative (and in the ... The TypeScript compiler supports the declaration of such...
Read more >
ProjectPathsConfig in ethers::solc - Rust - Docs.rs
Returns the first library that is an ancestor of the given file . ... has this remapping: @aave/=@aave/ (name:path) so contracts can be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found