Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript errors with the ethers added functionality, like ethers.getSigners() #6109

Closed
Muhammad-Altabba opened this issue Jan 5, 2025 · 5 comments
Assignees
Labels
status:needs-more-info There's not enough information to start working on this issue

Comments

@Muhammad-Altabba
Copy link

Version of Hardhat

2.22.17

What happened?

After importing "@nomicfoundation/hardhat-toolbox"; at hardhat.config.ts, the hardhat commands work. But compiling the project with tsc gives errors with the ethers added functionality, like ethers.getSigners().

Minimal reproduction steps

The project was created with pnpm add -D hardhat and npx hardhat init using the template Create a TypeScript project.

Here is the tsconfig.json file:

{
  "compilerOptions": {
    "target": "es2020",
    "module": "commonjs",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true,
    "resolveJsonModule": true,
    "outDir": "./build"
  }
}

And here is the hardhat.config.ts:

import { HardhatUserConfig } from "hardhat/config";
import '@nomicfoundation/hardhat-toolbox';

const config: HardhatUserConfig = {
  solidity: "0.8.28",
};

export default config;

Search terms

ethers

@ChristopherDedominici
Copy link
Contributor

Hi @Muhammad-Altabba, thanks for raising this question.
In a typical Hardhat project, there’s usually no need to compile your TypeScript code with tsc. Instead, you can just run your scripts with Hardhat:

npx hardhat run scripts/your-script.ts

If you do have a specific reason to compile your TS code independently (with tsc), could you share more about your use case? Sometimes issues can come from a misconfigured tsconfig.json. But in most scenarios, Hardhat scripts don’t need standalone compilation, hardhat run handles everything for you. Let us know if there’s a particular situation where you still need to compile your project!

@ChristopherDedominici ChristopherDedominici added status:needs-more-info There's not enough information to start working on this issue and removed status:triaging labels Jan 13, 2025
@Muhammad-Altabba
Copy link
Author

Thanks @ChristopherDedominici ,
It started when vscode showed errors in the TypeScript code created by npx hardhat init.
image

So, I wanted to double-check the issue's root cause. And I ran tsc that I supposed that it should be able to run to get this project compiled. And I think once tsc starts to give no errors, then vscode will also be able to acknowledge the types and provide IntelliSense accordingly.

So, if there is a way to let vscode identify the types correctly, without getting tsc to run correctly, then I think there are no issues. And in that case someone can use hardhat ....

Or what do you suggest?

@kanej
Copy link
Member

kanej commented Jan 16, 2025

Thanks @ChristopherDedominici , It started when vscode showed errors in the TypeScript code created by npx hardhat init. image

So, I wanted to double-check the issue's root cause. And I ran tsc that I supposed that it should be able to run to get this project compiled. And I think once tsc starts to give no errors, then vscode will also be able to acknowledge the types and provide IntelliSense accordingly.

So, if there is a way to let vscode identify the types correctly, without getting tsc to run correctly, then I think there are no issues. And in that case someone can use hardhat ....

Or what do you suggest?

Hey @Muhammad-Altabba can I check which package manager you are installing with, is it pnpm?

@Muhammad-Altabba
Copy link
Author

Muhammad-Altabba commented Jan 16, 2025

Hey @Muhammad-Altabba can I check which package manager you are installing with, is it pnpm?

Yes, it is pnpm. And I created the project with pnpm add -D hardhat and npx hardhat init using the template Create a TypeScript project.

@kanej
Copy link
Member

kanej commented Mar 11, 2025

I am going to close this. It looks like it was a temporary pnpm issue.

With the latest Hardhat I was able to:

mkdir v2-latest-ethers
cd v2-latest-ethers
pnpm init
pnpm add -D hardhat
npx hardhat init
# Select the Ethers/Typescript sample project
npx hardhat compile
tsc -b .
# Confirm that there are no JS/TS warnings in vscode when looking at `./test/Lock.ts`

@kanej kanej closed this as completed Mar 11, 2025
@github-project-automation github-project-automation bot moved this from Backlog to Done in Hardhat Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:needs-more-info There's not enough information to start working on this issue
Projects
Status: Done
Development

No branches or pull requests

3 participants