Open
Description
Bug report
- I confirm this is a bug with Supabase, not with my own application.
- I confirm I have searched the Docs, GitHub Discussions, and Discord.
Describe the bug
[Error] Error bundling script https://raw.githubusercontent.com/vircadia/vircadia-world-sdk-ts/refs/heads/master/seed/babylon/seed.ts: Error: Could not set the Deno root directory
at assert (https://jsr.io/@deno/cache-dir/0.8.0/util.ts:5:11)
at new DenoDir (https://jsr.io/@deno/cache-dir/0.8.0/deno_dir.ts:11:5)
at createCache (https://jsr.io/@deno/cache-dir/0.8.0/mod.ts:42:19)
at bundle (https://jsr.io/@deno/emit/0.45.0/mod.ts:61:19)
at file:///Users/aurora/Documents/Projects/Vircadia/vircadia-world-server/modules/supabase/app/supabase/functions/bundle/index.ts:41:31
at Array.map (<anonymous>)
at Object.handler (file:///Users/aurora/Documents/Projects/Vircadia/vircadia-world-server/modules/supabase/app/supabase/functions/bundle/index.ts:34:52)
at eventLoopTick (ext:core/01_core.js:168:7)
at async respond (ext:sb_core_main_js/js/http.js:163:14)
To Reproduce
Serve this function and call it with a .ts script to bundle:
import { bundle } from "jsr:@deno/emit";
// Set reasonable limits for bundling operations
const BUNDLE_TIMEOUT = 60000; // 60 seconds
const MAX_URLS = 50; // Maximum number of URLs to process
Deno.serve(async (req) => {
try {
const { urls } = await req.json();
// Validate input
if (!Array.isArray(urls)) {
return new Response(
JSON.stringify({ error: "URLs must be provided as an array" }),
{
status: 400,
headers: { "Content-Type": "application/json" },
},
);
}
// Enforce URL limit
if (urls.length > MAX_URLS) {
return new Response(
JSON.stringify({
error: `Cannot process more than ${MAX_URLS} URLs at once`,
}),
{
status: 400,
headers: { "Content-Type": "application/json" },
},
);
}
// Process URLs with timeout protection
const compiledScripts = await Promise.all(
urls.map(async (url: string) => {
try {
// Create a timeout promise
const timeoutPromise = new Promise((_, reject) => {
setTimeout(
() =>
reject(
new Error(`Bundling timed out for ${url}`),
),
BUNDLE_TIMEOUT,
);
});
// Bundle with timeout
const bundlePromise = bundle(new URL(url), {
allowRemote: true,
});
const result = await Promise.race([
bundlePromise,
timeoutPromise,
]);
return {
url,
code: result.code,
size: result.code.length,
};
} catch (error) {
console.error(`Error bundling script ${url}:`, error);
return {
url,
error: `Bundling error: ${error.message}`,
stack: Deno.env.get("ENVIRONMENT") === "development"
? error.stack
: undefined,
};
}
}),
);
return new Response(
JSON.stringify({
scripts: compiledScripts,
timestamp: new Date().toISOString(),
}),
{
headers: {
"Content-Type": "application/json",
"Cache-Control": "public, max-age=3600",
},
},
);
} catch (error) {
console.error("Server error:", error);
return new Response(
JSON.stringify({
error: error.message,
stack: Deno.env.get("ENVIRONMENT") === "development"
? error.stack
: undefined,
}),
{
status: 500,
headers: { "Content-Type": "application/json" },
},
);
}
});
Expected behavior
The Edge Runtime needs to (if not already) allow for Edge Functions to use a temporary cache in order to operate nominally.
System information
- OS: macOS (Supabase CLI 1.207.9)