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

Neither old (experimental) decorators nor new (stage 3) decorators work since upgrading to Deno 1.40 #296

Closed
2 tasks done
hammerlscs opened this issue Mar 22, 2024 · 11 comments · Fixed by #316
Closed
2 tasks done
Labels
bug Something isn't working released

Comments

@hammerlscs
Copy link

hammerlscs commented Mar 22, 2024

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

Neither the old (experimental) decorators nor the new (stage 3) decorators work since upgrading to Deno 1.40:

Setting up Edge Functions runtime...
Serving functions on http://localhost:54321/functions/v1/<function-name>

Using supabase-edge-runtime-1.38.0 (compatible with Deno v1.40.3)

serving the request with /home/deno/functions/test

Uncaught SyntaxError: Invalid or unexpected token
    at file:///home/deno/functions/test/index.ts:14:3

An error has occured

InvalidWorkerCreation: worker boot error
    at async UserWorker.create (ext:sb_user_workers/user_workers.js:141:15)
    at async Server.<anonymous> (file:///home/deno/main/index.ts:129:20)
    at async #respond (https://deno.land/std@0.182.0/http/server.ts:220:18) {
  name: "InvalidWorkerCreation"
}

The new stage 3 decorators possibly do not work because of: denoland/deno#22419

And the old experimental decorators possibly do not work, because using them requires the configuration

{
  "compilerOptions": {
    "experimentalDecorators": true
  }
}

(https://deno.com/blog/v1.40#decorators)

To Reproduce

Create either an edge function with the new stage 3 decorator syntax such as:

// deno-lint-ignore no-explicit-any
function trace(fn: any, ctx: ClassMethodDecoratorContext) {
    // deno-lint-ignore no-explicit-any
    return function (...args: unknown[]) {
        console.log("ENTERED", ctx.name);
        const v = fn(...args);
        console.log("EXITED", ctx.name);
        return v;
    };
}

class App {
    @trace
    static start() {
        console.log("Hello World!");
    }
}

Deno.serve(async (req) => {
    const { name } = await req.json()
    const data = {
        message: `Hello ${name}!`,
    }

    App.start();

    return new Response(JSON.stringify(data), { headers: { 'Content-Type': 'application/json' } })
})

Or create an edge function with the old experimental decorators such as:

function trace(
  // deno-lint-ignore no-explicit-any
  _target: any,
  _methodName: string,
  descriptor: PropertyDescriptor,
) {
  const originalMethod = descriptor.value

  // deno-lint-ignore no-explicit-any
  descriptor.value = function (...args: any[]) {
    console.log('ENTERED')
    const v = originalMethod.call(this, ...args)
    console.log('EXITED')
    return v
  }
  return descriptor
}

class App {
  @trace
  start() {
    console.log('Hello World!')
  }
}

Deno.serve(async (req) => {
  const { name } = await req.json()
  const data = {
    message: `Hello ${name}!`,
  }

  const app = new App()
  app.start()

  return new Response(JSON.stringify(data), { headers: { 'Content-Type': 'application/json' } })
})

Then call the edge function:

curl -i --location --request POST 'http://localhost:54321/functions/v1/test' \
  --header 'Authorization: Bearer SUPABASE_ANON_KEY' \
  --header 'Content-Type: application/json' \
  --data '{"name":"Is this working"}'

Expected behavior

The decorators work as expected

System information

Tested with Supabase CLI v1.150.0 and v1.151.0

@hammerlscs hammerlscs added the bug Something isn't working label Mar 22, 2024
@geoffreygarrett
Copy link

+1 🙏🏻

import { Service } from "npm:@bluelibs/core";


@Service()
class A {
  init() {
    return true;
  }
}

Results in:

Setting up Edge Functions runtime...

Serving functions on http://127.0.0.1:54321/functions/v1/<function-name>

Using supabase-edge-runtime-1.38.0 (compatible with Deno v1.40.3)

serving the request with /home/deno/functions/webhook

Uncaught SyntaxError: Invalid or unexpected token
    at file:///home/deno/functions/webhook/index.ts:7:1

I've had to rewrite part of an external library because of this.

@geoffreygarrett
Copy link

The core of the issue is that I'd like to use typedi which requires:

"emitDecoratorMetadata": true,
"experimentalDecorators": true,

Is it possible to have this set in the runtimes deno.json?

@hammerlscs
Copy link
Author

The core of the issue is that I'd like to use typedi which requires:

"emitDecoratorMetadata": true,
"experimentalDecorators": true,

Is it possible to have this set in the runtimes deno.json?

With "experimentalDecorators": true, only and exclusively the old experimental decorators would work. This would be an improvement, but it would be great, if we could use a deno.json config file instead of or in addition to the import_map.json file for the edge functions. With this we could control which decorators we want to use.

By then adding "experimentalDecorators": true, the old experimental decorators should work again. And as soon as denoland/deno#22419 is fixed and merged, the new stage 3 decorators should work again as well.

@geoffreygarrett
Copy link

The core of the issue is that I'd like to use typedi which requires:

"emitDecoratorMetadata": true,
"experimentalDecorators": true,

Is it possible to have this set in the runtimes deno.json?

With "experimentalDecorators": true, only and exclusively the old experimental decorators would work. This would be an improvement, but it would be great, if we could use a deno.json config file instead of or in addition to the import_map.json file for the edge functions. With this we could control which decorators we want to use.

By then adding "experimentalDecorators": true, the old experimental decorators should work again. And as soon as denoland/deno#22419 is fixed and merged, the new stage 3 decorators should work again as well.

It would be preferable to have access to the deno.json, but as it stands, they've decided to bundle it with the supabase-edge-runtime container, so either we all have it, or none of us do. I'm hoping it's non-impactful to everyone to have the above configuration added.

@louis-amhild
Copy link

louis-amhild commented Mar 26, 2024

I can confirm that decorators no longer work since edge-runtime upgraded to release v1.34.0 (87f8b69), which traces back to this PR in Deno, where experimentalDecorators was disabled as default (denoland/deno#22101).

My upcoming port of TSOA for Deno (https://github.com/louis-amhild/tsoa-deno) stopped working in Supabase and I couldn't understand why (thanks for posting this bug @hammerlscs).

As announced by the Deno team disabling experimentalDecorators is a very impactful change as "code that was deployed and executed successfully before the change might fail either at build time or runtime if it is redeployed now without any change." (https://deno.com/deploy/changelog#2024-02-22). However they have argued to make the change anyway as developers can just enable experimentalDecorators in the config - which is obviously not possible in Supabase and thous we have this issue.

Waiting for stage 3 decorators to be fixed in Deno (denoland/deno#22419) will only solve the issue partly, as the new decorators in typescript 5 has a different syntax and still lack features ie. “does not allow decorating parameters” for example
https://devblogs.microsoft.com/typescript/announcing-typescript-5-0-rc/#decorators.

I think @geoffreygarrett is right that enabling experimentalDecorators as default again is a good solution until Supabase introduces Deno config (some day?) or the stage 3 decorators are fully implemented and adopted in more libraries (in some years). Enabling it would solve the issue and return the previous behaviour as before edge v1.34.0.

Unfortunately I'm not really familiar with the code base so it is difficult for me to make a PR, but maybe someone else could? Maybe you know if it would be easy to enable experimentalDecorators again @andreespirela?

@andreespirela
Copy link
Collaborator

Sounds reasonable to me

@geoffreygarrett
Copy link

So, could we get it enabled in the runtime container's config for now?

Copy link

🎉 This issue has been resolved in version 1.43.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@nyannyacha
Copy link
Collaborator

I don't know if you are in a hosted or self-hosted environment, but if you are self-hosted, you can now enable the decorator feature (see this link).

If you are using a hosted (Supabase Cloud) environment, it will probably take a while for the decorator feature to be enabled.

@wave-light
Copy link

Can this please be re-opened? The issue is only fixed if you are running Supabase in a self-hosted environment.

@jsantos-godroplet
Copy link

jsantos-godroplet commented Jun 2, 2024

Can this please be re-opened? The issue is only fixed if you are running Supabase in a self-hosted environment.

@laktek Just got this error too. Can we reopen?

supabase-edge-runtime-1.53.3 (Deno v1.40.3)

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

Successfully merging a pull request may close this issue.

7 participants