Skip to content

Commit 035318b

Browse files
committed
fix: handle CJS default export wrapping in static adapter
1 parent f071f63 commit 035318b

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@markopack/adapter-static": patch
3+
---
4+
5+
Fix CJS module interop in static adapter's buildEnd: dynamic `import()` of a CJS bundle wraps exports under `.default`, so `fetch` was undefined. Now falls back to `mod.default?.fetch`.

packages/adapter-static/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ export default function staticAdapter(options: Options = {}): Adapter {
149149

150150
if (sourceEntries[0] === defaultEntry) {
151151
envFile && (await loadEnv(envFile));
152-
const fetch: Fetch = (await import(pathToFileURL(builtEntries[0]).href))
153-
.fetch;
152+
const mod = await import(pathToFileURL(builtEntries[0]).href);
153+
const fetch: Fetch = mod.fetch || mod.default?.fetch;
154154
const crawler = createCrawler(
155155
async (request) => {
156156
const response = await fetch(request, {});

0 commit comments

Comments
 (0)