dethcrypto / dethcrypto/TypeChain

Can't natively import typechains

Open
#668 4 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
2.8k
Forks
376
PR merge metrics
No merged PRs in 30d

Description

So, I got two projects.

ProjectA: Holds solidity smart contracts, and will be published to `npm` with `typechained` folder along some other stuff.
ProjectB: Will like to `import` those types.

The thing is that when I do import them (from node_modules), I keep having this error:

`bash
/{path}/typechained/index.ts:4
import type * as openzeppelin from "./@openzeppelin";
^^^^^^

SyntaxError: Cannot use import statement outside a module`

It seems that since typechains are exported in ESM I can not import them into another hardhat project (sicne it resolves with `module: commonjs`.

Is there an obvious fix that I'm not seeing? Is there a possibility of having `typechain` generate `commonjs` compatible code? As an example `@dethcrypto/eth-sdk` generates both a `ts` and a `cjs` folder.

Versions:
`
"hardhat": "2.9.2",
"ts-node": "10.7.0",
"typechain": "8.0.0",
"typescript": "4.6.3"`

tsconfig:
` {
"compilerOptions": {
"target": "es2019",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"forceConsistentCasingInFileNames": true,
"outDir": "dist",
"baseUrl": ".",
"paths": {
....
}
},
"include": ["./scripts", "./deploy", "./test"],
"files": ["./hardhat.config.ts"]
}
`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.