From 4a3b5c1d5fe96e5b43f3a4e1ec7bc6b0cbb62748 Mon Sep 17 00:00:00 2001 From: "Inomoto, Yota" <91780796+wiyota@users.noreply.github.com> Date: Sat, 7 Dec 2024 11:55:24 +0900 Subject: [PATCH] fix: mark async_hooks as external --- .changeset/shiny-knives-obey.md | 5 +++ .../src/buildApplication/buildWorkerFile.ts | 7 +++- .../processVercelFunctions/build.ts | 33 ++++++++++++------- 3 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 .changeset/shiny-knives-obey.md diff --git a/.changeset/shiny-knives-obey.md b/.changeset/shiny-knives-obey.md new file mode 100644 index 000000000..ded1d5f69 --- /dev/null +++ b/.changeset/shiny-knives-obey.md @@ -0,0 +1,5 @@ +--- +'@fleek-platform/next-on-fleek': patch +--- + +Mark `async_hooks` as external. diff --git a/packages/next-on-fleek/src/buildApplication/buildWorkerFile.ts b/packages/next-on-fleek/src/buildApplication/buildWorkerFile.ts index 01ac613b3..e49f4e3a1 100644 --- a/packages/next-on-fleek/src/buildApplication/buildWorkerFile.ts +++ b/packages/next-on-fleek/src/buildApplication/buildWorkerFile.ts @@ -88,7 +88,12 @@ export async function buildWorkerFile( banner: { js: generateGlobalJs() }, bundle: true, inject: [functionsFile], - external: ['node:*', './__next-on-fleek-dist__/*', 'cloudflare:*'], + external: [ + 'node:*', + 'async_hooks', + './__next-on-fleek-dist__/*', + 'cloudflare:*', + ], define: { __CONFIG__: JSON.stringify(vercelConfig), __NODE_ENV__: JSON.stringify(getNodeEnv()), diff --git a/packages/next-on-fleek/src/buildApplication/processVercelFunctions/build.ts b/packages/next-on-fleek/src/buildApplication/processVercelFunctions/build.ts index 6f52cdd3a..6dc77afe8 100644 --- a/packages/next-on-fleek/src/buildApplication/processVercelFunctions/build.ts +++ b/packages/next-on-fleek/src/buildApplication/processVercelFunctions/build.ts @@ -36,7 +36,13 @@ export async function buildFile( platform: 'neutral', outfile: filePath, bundle: true, - external: ['node:*', `${relativeNopDistPath}/*`, '*.wasm', 'cloudflare:*'], + external: [ + 'node:*', + 'async_hooks', + `${relativeNopDistPath}/*`, + '*.wasm', + 'cloudflare:*', + ], minify: false, plugins: [builtInModulesPlugin], loader: { '.ttf': 'file' }, @@ -96,21 +102,24 @@ type RelativePathOpts = { * breaks at runtime. The following fixes this by updating the dynamic require to a standard esm * import from the built-in module. * - * This applies to `require("node:*")` and `require("cloudflare:*")`. + * This applies to `require("node:*")`, `require("cloudflare:*")`, and `require("async_hooks")`. */ export const builtInModulesPlugin: Plugin = { name: 'built-in:modules', setup(build) { - build.onResolve({ filter: /^(node|cloudflare):/ }, ({ kind, path }) => { - /** - * This plugin converts `require(":*")` calls, those are the only ones that need - * updating (esm imports to ":*" are totally valid), so here we tag with the - * built-in-modules namespace only imports that are require calls. - */ - return kind === 'require-call' - ? { path, namespace: 'built-in-modules' } - : undefined; - }); + build.onResolve( + { filter: /^(node:|cloudflare:|async_hooks)/ }, + ({ kind, path }) => { + /** + * This plugin converts `require(":*")` calls, those are the only ones that need + * updating (esm imports to ":*" are totally valid), so here we tag with the + * built-in-modules namespace only imports that are require calls. + */ + return kind === 'require-call' + ? { path, namespace: 'built-in-modules' } + : undefined; + } + ); /** * We convert the imports we tagged with the built-in-modules namespace so that instead of