Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workers can`t dynamically import a string as typescript code #392

Open
localhosted opened this issue Jul 27, 2024 · 1 comment
Open

Workers can`t dynamically import a string as typescript code #392

localhosted opened this issue Jul 27, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@localhosted
Copy link

localhosted commented Jul 27, 2024

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 localhosted added the bug Something isn't working label Jul 27, 2024
@nyannyacha
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants