WSL Truffle import error: Could not find any sources

Hello all,

I’m a brand new dev and I’m having a really hard time getting my smart contract to compile. I looked around on the internet for hours and tried every solution I can find (including ones posted in this forum), but to no avail. I was using PowerShell, simply because I know the commands decently well. one solution said using WSL should fix it, it did not. I have tried all the ways to point to where the file is that I can find and nothing is working.

Error:

    Error: Could not find /mnt/c/Users/Jordan/Desktop/Real 
Website/node_modules/@openzeppelin/contracts/token/ERC20/ERC20Capped.sol from any 
sources; 
imported from /mnt/c/Users/Jordan/Desktop/Real Website/MoovItTest/contracts/MoovIt.sol
    at Resolver.<anonymous> 
(/mnt/c/Users/Jordan/AppData/Roaming/npm/node_modules/truffle
/build/webpack:/packages/resolver/ 
    dist/lib/resolver.js:54:1)
    at Generator.next (<anonymous>)
    at fulfilled 
  (/mnt/c/Users/Jordan/AppData/Roaming/npm/node_modules/truffle
/build/webpack:/packages/resolver/ 
dist/lib/resolver.js:5:42)
Truffle v5.1.44 (core: 5.1.44)
Node v10.22.0

Versions:

Truffle v5.1.44 (core: 5.1.44)
Solidity v0.5.16 (solc-js)
Node v10.22.0
Web3.js v1.2.1

Solidity file:

pragma solidity ^0.5.16;

import "../../node_modules/@openzeppelin/contracts/token/ERC20/ERC20Capped.sol";
import "../../node_modules/@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol";

contract MoovItTest is ERC20Capped, ERC20Detailed {

  constructor(string _name, string _symbol, uint8 _decimals, uint256 cap)
    DetailedERC20(_name, _symbol, _decimals)
    ERC20Capped(_cap)
    public
  {



  }

}

Any help would be greatly appreciated.

1 Like

Seems I was able to fix this by moving all contract dependencies out of the @openzeppelin folder and directly into my projects contracts folder then instructing solidity to look there.

1 Like

Hi @Proniss,

Welcome to the community :wave: and welcome to smart contract development.

I'm sorry you are having a hard time getting your contracts to compile. An easy way to start is with the following guide: Create an ERC20 using Truffle, without writing Solidity


You should be able to import as follows without having to use a relative path. This is what my imports look like:

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

I don't recommend copying the OpenZeppelin Contracts as you shouldn't modify them:

_From: https://docs.openzeppelin.com/contracts/3.x/#usage_
To keep your system secure, you should always use the installed code as-is, and neither copy-paste it from online sources, nor modify it yourself.


As an aside, I would suggest using either Solidity 0.6 or Solidity 0.7. The latest version of OpenZeppelin Contracts 3.2 has a Solidity 0.6 and a Solidity 0.7 version.

Feel free to ask all the questions that you need.

Hi @Proniss,

Checking to see if your were able to resolve?