Skip to content

Commit e265577

Browse files
committed
fix: add .js extensions to imports for Node.js native ESM compatibility
1 parent 8516683 commit e265577

File tree

5 files changed

+40
-8
lines changed

5 files changed

+40
-8
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"generate": "bun scripts/generate-preview.ts",
5050
"prebuild": "bun scripts/build-inline.js",
5151
"build": "tsc",
52+
"test:esm": "node test-esm.mjs",
5253
"prepublishOnly": "bun run build"
5354
},
5455
"type": "module",

src/generate-html.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { RouteInfo } from './collect-routes';
2-
import { DocsGeneratorOptions, RouteMeta } from './types';
3-
import { getStyles, getScripts, getLogo } from './assets-inline';
1+
import { RouteInfo } from './collect-routes.js';
2+
import { DocsGeneratorOptions, RouteMeta } from './types.js';
3+
import { getStyles, getScripts, getLogo } from './assets-inline.js';
44

55
/**
66
* Generate beautiful HTML documentation from route information

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
* @packageDocumentation
88
*/
99

10-
export { collectRoutes, type RouteInfo } from './collect-routes';
11-
export { generateDocsHtml } from './generate-html';
12-
export { type RouteMeta, type DocsGeneratorOptions } from './types';
10+
export { collectRoutes, type RouteInfo } from './collect-routes.js';
11+
export { generateDocsHtml } from './generate-html.js';
12+
export { type RouteMeta, type DocsGeneratorOptions } from './types.js';

test-esm.mjs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* ESM Smoke Test - Verifies Node.js native ESM compatibility
3+
* This should run without ERR_MODULE_NOT_FOUND errors
4+
*/
5+
6+
console.log('Testing ESM imports...');
7+
8+
try {
9+
// Test direct imports work without crashes
10+
const { collectRoutes, generateDocsHtml } = await import('./dist/index.js');
11+
12+
console.log('✅ Successfully imported collectRoutes:', typeof collectRoutes);
13+
console.log('✅ Successfully imported generateDocsHtml:', typeof generateDocsHtml);
14+
15+
// Verify they are the expected types
16+
if (typeof collectRoutes !== 'function') {
17+
throw new Error('collectRoutes should be a function');
18+
}
19+
if (typeof generateDocsHtml !== 'function') {
20+
throw new Error('generateDocsHtml should be a function');
21+
}
22+
23+
console.log('\n✅ ESM compatibility test PASSED');
24+
console.log('All imports resolved correctly with .js extensions');
25+
process.exit(0);
26+
} catch (error) {
27+
console.error('\n❌ ESM compatibility test FAILED');
28+
console.error('Error:', error.message);
29+
console.error('\nStack:', error.stack);
30+
process.exit(1);
31+
}

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"compilerOptions": {
33
"target": "ES2022",
4-
"module": "ES2022",
4+
"module": "Node16",
55
"lib": ["ES2022"],
6-
"moduleResolution": "bundler",
6+
"moduleResolution": "node16",
77
"declaration": true,
88
"declarationMap": true,
99
"outDir": "./dist",

0 commit comments

Comments
 (0)