'HardHat: Nothing to compile

When compiling the hardhat project When it's showing Nothing to Compile.

{
  "name": "HardhAtToken",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@nomiclabs/hardhat-ethers": "^2.0.6",
    "@nomiclabs/hardhat-waffle": "^2.0.3",
    "chai": "^4.3.6",
    "ethereum-waffle": "^3.4.4",
    "ethers": "^5.6.6",
    "hardhat": "^2.9.6-dev.1"
  },
  "dependencies": {
    "glob": "^7.2.0"
  }
}


Solution 1:[1]

Hardhat keeps a cache of compiled contracts in the cache project folder.

The npx hardhat compile command only compiles files that have not been changed since the last compilation. So the "nothing to compile" message is expected in your case.

You can either clear the cache using npx hardhat clean, or force recompilation of cached sources using the npx hardhat compile --force argument.

Docs: https://hardhat.org/guides/compile-contracts.html

Solution 2:[2]

You can either use call or apply here as:

const result = small.func.call(large, 2, 3, 5);

What above statement means is that You are taking the function(or can say borrowing) small.func function and applying in the context of large object with argument 2, 3, 5.

const small = {
  a: 1,
  func: function(b, c, d) {
    return this.a + b + c + d;
  },
};

const large = {
  a: 5,
};

   const result = small.func.call(large, 2, 3, 5);
// const result = small.func.apply(large, [2, 3, 5]);
console.log(result);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Petr Hejda
Solution 2 decpk