slither icon indicating copy to clipboard operation
slither copied to clipboard

crytic_compile.platform.exceptions.InvalidCompilation: Unknown file: @openzeppelin/contracts-upgradeable/introspection/ERC165Upgradeable.sol

Open jacobrosenthal opened this issue 3 years ago • 6 comments

$ slither .
'npx hardhat compile --force' running
Compiling 28 files with 0.7.6
Compilation finished successfully
Creating Typechain artifacts in directory /home/proj/packages/contracts/typechain for target ethers-v5
Successfully generated Typechain artifacts!

Traceback (most recent call last):
  File "/home/proj/.local/lib/python3.9/site-packages/slither/__main__.py", line 723, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/home/proj/.local/lib/python3.9/site-packages/slither/__main__.py", line 71, in process_all
    compilations = compile_all(target, **vars(args))
  File "/home/proj/.local/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 489, in compile_all
    compilations.append(CryticCompile(target, **kwargs))
  File "/home/proj/.local/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 109, in __init__
    self._compile(**kwargs)
  File "/home/proj/.local/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 417, in _compile
    self._platform.compile(self, **kwargs)
  File "/home/proj/.local/lib/python3.9/site-packages/crytic_compile/platform/hardhat.py", line 118, in compile
    contract_filename = convert_filename(
  File "/home/proj/.local/lib/python3.9/site-packages/crytic_compile/utils/naming.py", line 102, in convert_filename
    raise InvalidCompilation(f"Unknown file: {filename}")
crytic_compile.platform.exceptions.InvalidCompilation: Unknown file: @openzeppelin/contracts-upgradeable/introspection/ERC165Upgradeable.sol
ERROR:root:None
ERROR:root:Error in .
ERROR:root:Traceback (most recent call last):
  File "/home/proj/.local/lib/python3.9/site-packages/slither/__main__.py", line 723, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/home/proj/.local/lib/python3.9/site-packages/slither/__main__.py", line 71, in process_all
    compilations = compile_all(target, **vars(args))
  File "/home/proj/.local/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 489, in compile_all
    compilations.append(CryticCompile(target, **kwargs))
  File "/home/proj/.local/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 109, in __init__
    self._compile(**kwargs)
  File "/home/proj/.local/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 417, in _compile
    self._platform.compile(self, **kwargs)
  File "/home/proj/.local/lib/python3.9/site-packages/crytic_compile/platform/hardhat.py", line 118, in compile
    contract_filename = convert_filename(
  File "/home/proj/.local/lib/python3.9/site-packages/crytic_compile/utils/naming.py", line 102, in convert_filename
    raise InvalidCompilation(f"Unknown file: {filename}")
crytic_compile.platform.exceptions.InvalidCompilation: Unknown file: @openzeppelin/contracts-upgradeable/introspection/ERC165Upgradeable.sol

ERC165Upgradeable Isnt used anywhere in the projects solidity files, but ERC721Upgradeable is which looks like it imports ERC165Upgradeable

Ubuntu 21.04 Silther 0.8.0

    "hardhat": "^2.1.1",
    "@openzeppelin/contracts-upgradeable": "^3.4.1-solc-0.7-2",
  solidity: {
    version: '0.7.6',
    settings: {
      optimizer: {
        enabled: true,
        runs: 200,
      },
    },
  },

jacobrosenthal avatar May 17 '21 00:05 jacobrosenthal

Did you ever resolve this?

0xfoobar avatar Aug 11 '21 22:08 0xfoobar

Did you ever resolve this?

luuuuo avatar Aug 12 '21 07:08 luuuuo

Hi @jacobrosenthal. Thank you for reporting this

Did you run npm install? If so, can you share the codebase where this happens?

montyly avatar Aug 12 '21 11:08 montyly

This error was thrown from here: https://github.com/crytic/crytic-compile/blob/master/crytic_compile/utils/naming.py#L109

Just make sure the @openzeppelin library is in one of these directory:

cwd.joinpath(Path("node_modules"), filename)
cwd.joinpath(Path("contracts"), filename)
working_dir.joinpath(filename)

sc0Vu avatar Oct 09 '21 10:10 sc0Vu

they are for me but that doesn't seem to resolve the issue. I'm still getting a "File not found" error

Philogy avatar Jan 24 '22 15:01 Philogy

This is especially sticky for monorepo projects where something like @openzeppelin/* is not installed in the relative node_modules/ but in the root workspace. Yarn 2 removed nohoist as well, so I haven't really found a good solution to this yet.

A temporary workaround is to symlink the relevant packages into the relative/workspace's node_modules/ dir but that gets pretty annoying and is temporary.

ETA: A solution is adding the following to the package.json for the contract package:

"installConfig": {
  "hoistingLimits": "dependencies"
},

mikeshultz avatar Apr 28 '22 15:04 mikeshultz