Skip to content

Getting "Must call super constructor in derived class before accessing 'this' or returning from derived constructor" #1

Open
@jcheese1

Description

@jcheese1

Repro:

  1. create fresh DO and workers project npm create cloudflare-latest

Paste from example:

import { DurableObject } from "cloudflare:workers";
import { Browsable } from "@outerbase/browsable-durable-object";

@Browsable()
export class MyDurableObject extends DurableObject<Env> {
	public sql: SqlStorage;

	constructor(ctx: DurableObjectState, env: Env) {
		super(ctx, env);
		this.sql = ctx.storage.sql;
	}

	async fetch(request: Request): Promise<Response> {
		return new Response("Hello from MyDurableObject");
	}
}

export default {
	async fetch(
		request: Request,
		env: Env,
		ctx: ExecutionContext,
	): Promise<Response> {
		const path = new URL(request.url).pathname;
		const id: DurableObjectId = env.MY_DURABLE_OBJECT.idFromName(path);
		const stub = env.MY_DURABLE_OBJECT.get(id);

		return stub.fetch(request);
	},
} satisfies ExportedHandler<Env>;
  1. run npm run start and access localhost

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions