hardhat-vscode icon indicating copy to clipboard operation
hardhat-vscode copied to clipboard

Validation is blocked on the entire project when there's an invalid import on a single file.

Open antico5 opened this issue 3 years ago • 8 comments
trafficstars

As the title says, if at least 1 file has an invalid import (either relative or library import), the validation gets blocked for all files in the project. The expected behavior is that the diagnostic is shown for the file with the error, and other files are validated normally.

antico5 avatar Aug 19 '22 13:08 antico5

I am running into this same issue, it started in version 0.4.5 and is still broken, I keep my projects using 0.4.4 and it's working, but i'd like the new features..

JacobRhiel avatar Aug 19 '22 21:08 JacobRhiel

I am running into this same issue, it started in version 0.4.5 and is still broken, I keep my projects using 0.4.4 and it's working, but i'd like the new features..

@JacobRhiel hey we definitely want you to be getting the new features! Could we get some more details?

Are you getting a validation issue with a bad import in a dependent file? What happens if you resolve the import issue?

kanej avatar Aug 22 '22 10:08 kanej

@kanej

So, most features work, but the most important, syntax highlighting and compilation.

  • npx hardhat for TS produces the same error on the below setup, with no extra files and bare minimum configuration.

It only displays this error on 0.4.5 and newer, but gives no insight.

No syntax highlighting on any version (other features work, just not compilation):

Versions:

NPM: 8.16.0 Node: 18.7.0

"devDependencies": {
    "@nomicfoundation/hardhat-toolbox": "^1.0.2",
    "hardhat": "^2.10.1",
    "hardhat-abi-exporter": "^2.10.0",
    "hardhat-contract-sizer": "^2.6.1",
    "hardhat-dependency-compiler": "^1.1.3",
    "hardhat-storage-layout": "^0.1.6",
    "prettier-plugin-solidity": "^1.0.0-dev.23"
  },
  "dependencies": {
    "@openzeppelin/contracts": "^4.7.0",
    "@openzeppelin/contracts-upgradeable": "^4.7.3",
    "dotenv": "^16.0.1"
  }

hardhat.config.ts:


import { HardhatUserConfig, task } from "hardhat/config";

import "@nomicfoundation/hardhat-toolbox";  // https://www.npmjs.com/package/@nomicfoundation/hardhat-toolbox
import "hardhat-dependency-compiler";       // https://www.npmjs.com/package/hardhat-dependency-compiler
import "hardhat-storage-layout";            // https://www.npmjs.com/package/hardhat-storage-layout
import "hardhat-contract-sizer";            // https://www.npmjs.com/package/hardhat-contract-sizer
import "hardhat-abi-exporter";              // https://www.npmjs.com/package/hardhat-abi-exporter

/* task("accounts", "Prints the list of accounts", async (_, {ethers}) => {
  const accounts = await ethers.getSigners();

  for (const account of accounts) {
    console.log(account.address);
  }
}); */

dotenv.config();

const config: HardhatUserConfig = {
  solidity: {
    version: process.env.COMPILE_VERSION || "0.8.16",
    settings: {
      optimizer: {
        enabled: process.env.OPTIMIZER == "true",
        runs: process.env.OPTIMIZER_RUNS || 200,
      },
      outputSelection: {
        "*": {
          "*": ["storageLayout"],
        },
      }
    },
  },
  gasReporter: {
    enabled: process.env.REPORT_GAS == "true"
  },
  defaultNetwork: process.env.DEFAULT_NETWORK || "hardhat",
  networks: {
    rinkeby: {
      url: process.env.RINKEBY_URI || "",
      accounts: process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
    },
  },
  etherscan: {
    apiKey: process.env.ETHERSCAN_API_KEY
  },
  dependencyCompiler: { // add your dependencies here
    paths: [
    ],
  },
  abiExporter: {
    runOnCompile: process.env.ABI_EXPORTER == "true",
    only: [],
  }
};

export default config;

Also, just trying CLI compilation produces this error on all versions:

> npx hardhat compile

Generating typings for: 3 artifacts in dir: typechain-types for target: ethers-v5
An unexpected error occurred:

TypeError: Cannot read properties of undefined (reading 'filter')
    at lowestCommonPath (E:\blockchain\polygon\seven-seas\asset-generation-contracts\node_modules\typechain\src\utils\files\lowestCommonPath.ts:3:36)
    at detectInputsRoot (E:\blockchain\polygon\seven-seas\asset-generation-contracts\node_modules\typechain\src\utils\files\detectInputsRoot.ts:7:108)
    at runTypeChain (E:\blockchain\polygon\seven-seas\asset-generation-contracts\node_modules\typechain\src\typechain\runTypeChain.ts:29:31)
    at SimpleTaskDefinition.action (E:\blockchain\polygon\seven-seas\asset-generation-contracts\node_modules\@typechain\hardhat\src\index.ts:87:38)
    at Environment._runTaskDefinition (E:\blockchain\polygon\seven-seas\asset-generation-contracts\node_modules\hardhat\src\internal\core\runtime-environment.ts:219:35)
    at Environment.run (E:\blockchain\polygon\seven-seas\asset-generation-contracts\node_modules\hardhat\src\internal\core\runtime-environment.ts:131:25)
    at OverriddenTaskDefinition._action (E:\blockchain\polygon\seven-seas\asset-generation-contracts\node_modules\@typechain\hardhat\src\index.ts:31:11)
    at async Environment._runTaskDefinition (E:\blockchain\polygon\seven-seas\asset-generation-contracts\node_modules\hardhat\src\internal\core\runtime-environment.ts:219:14)
    at async Environment.run (E:\blockchain\polygon\seven-seas\asset-generation-contracts\node_modules\hardhat\src\internal\core\runtime-environment.ts:131:14)
    at async SimpleTaskDefinition.action (E:\blockchain\polygon\seven-seas\asset-generation-contracts\node_modules\hardhat\src\builtin-tasks\compile.ts:1358:63)```

JacobRhiel avatar Aug 22 '22 16:08 JacobRhiel

The link to the error location improves the UX, but to fully resolve the issue we need whole project diagnostics.

kanej avatar Aug 31 '22 11:08 kanej

Just an update on my portion of this issue.

It just gets stuck on 'validator starting', hardhat.config.ts has a check mark.

image

JacobRhiel avatar Sep 15 '22 22:09 JacobRhiel

Hey @JacobRhiel, if you make a further edit in the open editor does the validator starting message change?

kanej avatar Sep 20 '22 09:09 kanej

yes, on VSCode launch I got "Validation blocked - validator starting" and after editing a .sol file I got "Validation blocked - unable to load hardhat config" but the checkmark hardhat.config.js stayed

pemmenegger avatar Sep 22 '22 12:09 pemmenegger

@pemmenegger validation depends on being able to compile with hardhat. If the extension cannot read the hardhat.config.js we cannot get any further in the process. If you try and run npx hardhat compile for the project with that hardhat.config.js, do you get more details?

kanej avatar Sep 26 '22 09:09 kanej

Closing this since with 0.6.0 the compilation process was changed and now unrelated contracts don't prevent validation on current file.

antico5 avatar Dec 27 '22 16:12 antico5