Skip to content

Import extensions when using with node native ES imports and TS support #19

@jabuj-amalytix

Description

@jabuj-amalytix

Hello! Thank you a lot for the library. I'm trying to apply it to my project, however I have issues with the file extensions in the generated files.

I'm using node 24, which has type stripping and ES module support enabled by default. For ES imports to work the extensions must be specified verbatim. However, the imports from ts-sql-query use .js extension, and my project is written in typescript, so it uses .ts. To make ts-sql-query imports work I have to specify output.import.extension = '.js'. This kind of sort of works, the generated file has

import { Table } from "ts-sql-query/Table.js";
import type { DBConnection } from "../db/connection-source.js";

The second import doesn't break immediately, because it is type-only and ignored by node, and typescript picks it up regardless of the extension. However if I add custom fieldMappings, it breaks

// config
fieldMappings: [
    {
      columnType: 'real',
      generatedField: {
        type: {
          kind: 'customDouble',
          dbType: { name: 'real' },
          adapter: {
            name: 'testDouble', importPath: './test-double.ts', isDefault: true
          },
        },
      },
    },
]
// generated file
import { Table } from "ts-sql-query/Table.js";
import type { DBConnection } from "../db/connection-source.js";
import testDouble from "../test-double.ts.js"; // This import fails

So the suggestion would be either to always add a .js extension to the ts-sql-query imports (I think this should work with CJS as well?) or apply output.import.extension only to ts-sql-query imports (for all other imports I'm in direct control of the extension anyway, I can specify it explicitly in connectionSource.path or importPath in fieldMappings). Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions