dethcrypto / TypeChain

🔌 TypeScript bindings for Ethereum smart contracts
MIT License
2.76k stars 365 forks source link

Add node16-modules flag to support Node16/NodeNext modules resolutions #799

Closed silasdavis closed 1 year ago

silasdavis commented 1 year ago

TypeScript's Node16/NodeNext module resolution brings uniform native ESM module support to Node/ESM environments as well as support for multiple entrypoints via package.json exports. However it explicitly requires relative imports to use file extensions for modules, usually '.js'.

This change introduces a node16Modules codegen config. Currently it just adds the module suffix .js to imports and exports where needed.

Without this it is impossible to use Typechain generated code with tsconfig moduleResolution: Node16 or NodeNext.

Signed-off-by: Silas Davis silas.davis@monaxlabs.io

changeset-bot[bot] commented 1 year ago

⚠️ No Changeset found

Latest commit: bbb3c18c57697b114d3c780efbe284d02cf40579

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

krzkaczor commented 1 year ago

Thanks @silasdavis! Can u take a look at failing tests?

silasdavis commented 1 year ago

Oops, yeah I will try to get round to that

pablomendezroyo commented 1 year ago

kind bump for this feature. The current documentation is encouraging users that using @typechain/ethers-v6 set the moduleResolution to either: nodenext or node16. This is incompatible with the types generated by typechain due to the missing extension .js

krzkaczor commented 1 year ago

Merged as: https://github.com/dethcrypto/TypeChain/pull/840