Skip to content

Commit c10a154

Browse files
patch loadInstrumentationModule
1 parent cce2a50 commit c10a154

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

packages/cloudflare/src/cli/build/build-worker.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,23 @@ export function patchEnhanceGlobals(code: string) {
151151
);
152152
}
153153

154+
/**
155+
*
156+
* `loadInstrumentationModule` (https://github.com/vercel/next.js/blob/5b7833e3/packages/next/src/server/next-server.ts#L301)
157+
* calls `module.findSourceMap` (https://nodejs.org/api/module.html#modulefindsourcemappath) which we haven't implemented
158+
* causing a runtime error.
159+
*
160+
* TODO: this should ideally be done in a more robust way with ts-morph
161+
*
162+
* TODO: investigate and better understand the issue, is it ok to skip this function?
163+
*/
164+
export function patchLoadInstrumentationModule(code: string) {
165+
return code.replaceAll(
166+
`async loadInstrumentationModule() {`,
167+
`async loadInstrumentationModule() { return;`
168+
);
169+
}
170+
154171
/**
155172
* This function applies string replacements on the bundled worker code necessary to get it to run in workerd
156173
*
@@ -173,6 +190,7 @@ async function updateWorkerBundledCode(workerOutputFile: string, config: Config)
173190
patchedCode = inlineMiddlewareManifestRequire(patchedCode, config);
174191
patchedCode = patchExceptionBubbling(patchedCode);
175192
patchedCode = patchEnhanceGlobals(patchedCode);
193+
patchedCode = patchLoadInstrumentationModule(patchedCode);
176194

177195
await writeFile(workerOutputFile, patchedCode);
178196
}

0 commit comments

Comments
 (0)