edge-runtime icon indicating copy to clipboard operation
edge-runtime copied to clipboard

Workers can`t dynamically import a string as typescript code

Open localhosted opened this issue 1 year ago • 1 comments

Bug report

  • [x ] I confirm this is a bug with Supabase, not with my own application.
  • [ x] I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

It`s not possible to import typescrpit code as a string dynamically

To Reproduce

Add the following code to any of the examples:

async function importjs(js: string, filename = "importedjs") {
    const dataUri =
      "data:text/typescript;charset=utf-8," +
      encodeURIComponent(js) +
      `//# sourceURL=${filename}.ts;`;
    const r = await import(/* @vite-ignore */ dataUri);
    return r;
  }

  const r = await importjs(`export default (arg1:any) => {return 'hello world '+arg1}`)
  console.log(r.default("test")) // EXPECTED: hello world test

The worker will error complaining about typescript sintax

{ "error": "Unexpected token ':' at data:text/typescript;charset=utf-8,export%20default%20(arg1%3Aany)%20%3D%3E%20%7Breturn%20'hello%20world%20'%2Barg1%7D//#%20sourceURL=importedjs.ts;:1:21" }

Expected behavior

Typescript code should work

System information

  • OS: Windows WSL 2, Oracle Linux

localhosted avatar Jul 27 '24 21:07 localhosted

Note:

I was able to reproduce it locally. This issue was caused by passing the original content as it is to deno_core without lowering it to Javascript.

nyannyacha avatar Jul 29 '24 00:07 nyannyacha

🔕 This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Aug 21 '25 02:08 github-actions[bot]