From e05a210b39ff228e2cd34968acfadfb981724cf9 Mon Sep 17 00:00:00 2001 From: J M Rossy Date: Mon, 1 Apr 2024 16:15:11 -0400 Subject: [PATCH 1/2] Fix for barrel file codegen of type-only files --- packages/typechain/src/codegen/createBarrelFiles.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/typechain/src/codegen/createBarrelFiles.ts b/packages/typechain/src/codegen/createBarrelFiles.ts index f1e764db..2df569e1 100644 --- a/packages/typechain/src/codegen/createBarrelFiles.ts +++ b/packages/typechain/src/codegen/createBarrelFiles.ts @@ -54,16 +54,15 @@ export function createBarrelFiles( .map((p) => { const namespaceIdentifier = normalizeDirName(p) + const fromFilePath = moduleSuffix ? `'./${p}/index${moduleSuffix}'` : `'./${p}'` + if (typeOnly) return [ - `import type * as ${namespaceIdentifier} from './${p}';`, + `import type * as ${namespaceIdentifier} from ${fromFilePath};`, `export type { ${namespaceIdentifier} };`, ].join('\n') - if (moduleSuffix) { - return `export * as ${namespaceIdentifier} from './${p}/index${moduleSuffix}';` - } - return `export * as ${namespaceIdentifier} from './${p}';` + return `export * as ${namespaceIdentifier} from ${fromFilePath};` }) .join('\n') From 302134acbfd8b8b297c3becb27714eb027bc53de Mon Sep 17 00:00:00 2001 From: J M Rossy Date: Mon, 1 Apr 2024 16:19:18 -0400 Subject: [PATCH 2/2] Add changeset file for barrel file fix --- .changeset/hungry-noodle-dryer.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/hungry-noodle-dryer.md diff --git a/.changeset/hungry-noodle-dryer.md b/.changeset/hungry-noodle-dryer.md new file mode 100644 index 00000000..610cbb92 --- /dev/null +++ b/.changeset/hungry-noodle-dryer.md @@ -0,0 +1,5 @@ +--- +'typechain': patch +--- + +Fix the import syntax for barrel file imports referring to type-only files. Fixes a problem with ESM compatibility when using the `--node16-modules` flag. \ No newline at end of file