Skip to content

Commit 23fb195

Browse files
committed
loader.ts — resolve Ajv default export so tsc + ESM interop both work
Plain `import Ajv from 'ajv'` works at runtime (Node ESM, Vite) but tsc with NodeNext sees Ajv as a namespace, not a constructor. Use namespace import + runtime resolution of `.default ?? namespace` to satisfy both.
1 parent 9001af5 commit 23fb195

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

ts/appTemplates/loader.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@
1515
* const tpl = await loadTemplateFromUrl(url); // fetches then validates
1616
*/
1717

18-
import Ajv, { type ErrorObject, type ValidateFunction } from 'ajv';
18+
import * as AjvNs from 'ajv';
19+
import type { ErrorObject, ValidateFunction } from 'ajv';
20+
21+
// Ajv ships an ESM default + CJS interop. `default` may be the class itself
22+
// or the namespace depending on bundler. Resolve once at load.
23+
const Ajv: any = (AjvNs as any).default ?? AjvNs;
1924
import { HDSLibError } from '../errors.ts';
2025
import schema from './schemas/appTemplate.schema.json' with { type: 'json' };
2126
import type { AppTemplate, CustomFieldDeclaration, ExistingStreamRef } from './templateTypes.ts';
2227

2328
const ajv = new Ajv({ allErrors: true, strict: false });
24-
const validate: ValidateFunction<AppTemplate> = ajv.compile<AppTemplate>(schema as any);
29+
const validate: ValidateFunction<AppTemplate> = ajv.compile(schema as any);
2530

2631
/** Validate the JSON shape (Ajv) and run cross-field rules. Returns the validated AppTemplate or throws HDSLibError. */
2732
export function loadTemplate (json: unknown): AppTemplate {

0 commit comments

Comments
 (0)