Skip to content

Commit 9fcd960

Browse files
committed
fix: load commander via dynamic import for ESM compatibility
Commander 15 is ESM only and cannot be required from CommonJS modules. Switch to dynamic import in CLI.run() and convert the static import to a type-only import with resolution-mode so tsc accepts it under module: node16.
1 parent a37cff6 commit 9fcd960

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎src/cli.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Command } from 'commander';
1+
import type { Command } from 'commander' with { 'resolution-mode': 'import' };
22
import { existsSync, readFileSync } from 'fs';
33
import path from 'path';
44
import { serve } from './server/server';
@@ -12,7 +12,8 @@ export class CLI {
1212
run(): Promise<void> {
1313
return this.requireOpen()
1414
.then(async (open) => {
15-
const program = new Command();
15+
const { Command } = await this.requireCommander();
16+
const program: Command = new Command();
1617

1718
const packageJsonPath = path.join(__dirname, '..', 'package.json');
1819
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
@@ -68,4 +69,8 @@ export class CLI {
6869
requireOpen(): Promise<(file: string) => void> {
6970
return import('open').then((module) => module.default);
7071
}
72+
73+
requireCommander(): Promise<typeof import('commander', { with: { 'resolution-mode': 'import' } })> {
74+
return import('commander');
75+
}
7176
}

0 commit comments

Comments
 (0)