Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/hungry-noodle-dryer.md
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 4 additions & 5 deletions packages/typechain/src/codegen/createBarrelFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down