Skip to content

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

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: something isn't workingreleased

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions