Skip to content

Commit 7fced0f

Browse files
authored
fix: enable using workerd process v2 (#903)
1 parent 17a4bea commit 7fced0f

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

.changeset/stale-adults-divide.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
fix: enable using workerd process v2
6+
7+
process v2 is an updated version of `node:process` active by default after 2025-09-15

examples/playground15/wrangler.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "node_modules/wrangler/config-schema.json",
33
"main": ".open-next/worker.js",
44
"name": "playground15",
5-
"compatibility_date": "2024-12-30",
5+
"compatibility_date": "2025-09-15",
66
"compatibility_flags": ["nodejs_compat", "global_fetch_strictly_public", "enable_request_signal"],
77
"assets": {
88
"directory": ".open-next/assets",

packages/cloudflare/src/cli/build/bundle-server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { inlineFindDir } from "./patches/plugins/find-dir.js";
1616
import { patchInstrumentation } from "./patches/plugins/instrumentation.js";
1717
import { inlineLoadManifest } from "./patches/plugins/load-manifest.js";
1818
import { patchNextServer } from "./patches/plugins/next-server.js";
19-
import { patchResolveCache } from "./patches/plugins/open-next.js";
19+
import { patchResolveCache, patchSetWorkingDirectory } from "./patches/plugins/open-next.js";
2020
import { handleOptionalDependencies } from "./patches/plugins/optional-deps.js";
2121
import { patchPagesRouterContext } from "./patches/plugins/pages-router-context.js";
2222
import { patchDepdDeprecations } from "./patches/plugins/patch-depd-deprecations.js";
@@ -107,6 +107,7 @@ export async function bundleServer(buildOpts: BuildOptions, projectOpts: Project
107107
patchRouteModules(updater, buildOpts),
108108
patchDepdDeprecations(updater),
109109
patchResolveCache(updater, buildOpts),
110+
patchSetWorkingDirectory(updater, buildOpts),
110111
// Apply updater updates, must be the last plugin
111112
updater.plugin,
112113
] as Plugin[],

packages/cloudflare/src/cli/build/patches/plugins/open-next.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,32 @@ rule:
4545
fix: |-
4646
var composableCacheHandlerPath = "";
4747
`;
48+
49+
export function patchSetWorkingDirectory(updater: ContentUpdater, buildOpts: BuildOptions): Plugin {
50+
const { outputDir } = buildOpts;
51+
const packagePath = getPackagePath(buildOpts);
52+
const outputPath = path.join(outputDir, "server-functions/default");
53+
54+
const indexPath = path.relative(
55+
buildOpts.appBuildOutputPath,
56+
path.join(outputPath, packagePath, `index.mjs`)
57+
);
58+
59+
return updater.updateContent("do-not-set-working-directory", [
60+
{
61+
filter: getCrossPlatformPathRegex(indexPath),
62+
contentFilter: /function setNextjsServerWorkingDirectory\(/,
63+
callback: async ({ contents }) => patchCode(contents, workingDirectoryRule),
64+
},
65+
]);
66+
}
67+
68+
// `setNextjsServerWorkingDirectory` calls `process.chdir("")` which errors because the directory does not exists
69+
// See https://github.com/opennextjs/opennextjs-cloudflare/issues/899
70+
export const workingDirectoryRule = `
71+
rule:
72+
pattern: function setNextjsServerWorkingDirectory() { $$$BODY }
73+
fix: |-
74+
function setNextjsServerWorkingDirectory() {
75+
}
76+
`;

0 commit comments

Comments
 (0)