TypeChain: hardhat task from dedicated file -- fails to build with Typechain import

Problem: cant use hardhat if task imports typechain contract; task has to be defined in dedicated file and imported into hardhat config;

Reproduce: https://github.com/rad-p/TypeChain/commit/128b6020cb73c9d5521a0e037bdec0efa9d8c24b

can’t use yarn hardhat

call:

 .../TypeChain/examples/hardhat
❯ yarn hardhat typechain

yarn run v1.22.10
$ /home/mr13/projects/ethereum-ts/TypeChain/examples/hardhat/node_modules/.bin/hardhat typechain
An unexpected error occurred:

tasks/counter.ts:2:23 - error TS2307: Cannot find module '../typechain' or its corresponding type declarations.

2 import {Counter} from "../typechain";
                        ~~~~~~~~~~~~~~

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

env:

❯ node --version
v14.16.1
 
❯ yarn --version
1.22.10

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 21 (12 by maintainers)

Commits related to this issue

Most upvoted comments

agree to reopen this

The only workaround I know works is using import type {...} from "...", and running TS_NODE_TRANSPILE_ONLY=1 npx hardhat compile.

TS_NODE_TRANSPILE_ONLY=1 npx hardhat typechain

This workaround does not work for me.

The only way I can workaround from this is to require the type dynamically, losing the purpose of having the type information.

Can you post a link to a repo so that I can take a look, @tuler ?

There’s a workaround that’s running TS_NODE_TRANSPILE_ONLY=1 npx hardhat typechain first.

We are looking for ways to fix this, but it’s not clear yet how, nor we can prioritize it yet.

@mr13tech ahh yes I think this is a problem with ts-node. You need to ensure that types are generated before running tests. Hardhat team tries to come up with a fix for this AFAIK.

Please refer to this example: https://github.com/ethereum-ts/TypeChain/tree/master/examples/hardhat

As @julianlen mentioned, probably it’s tsconfig.json misconfiguration.

Check the tsconfig.json file if it has "include": ["./hardhat.config.ts","./scripts","src/**/*", "**/*.ts","./test", "typechain/**/*"],

The same for hardhat.config.ts check if you are importing import "@typechain/hardhat"