ComponentizeJS icon indicating copy to clipboard operation
ComponentizeJS copied to clipboard

ReferenceError when resource has no functions

Open tomasol opened this issue 8 months ago • 1 comments

Having an empty resource:

interface execution {

    resource join-set-id {
        // id: func() -> string;
    }

  new-join-set: func() -> join-set-id;
}

Calling new-join-set from a JavaScript guest fails with an error: ReferenceError: import_execution_1_0_0$JoinSetId is not defined. This is because the generated initializer.jsdoes not contain class import_execution_1_0_0$JoinSetId {...}, but tries to use it in the generated new-join-set function: var rsc2 = new.target === import_execution_1_0_0$JoinSetId ? this : Object.create(import_execution_1_0_0$JoinSetId.prototype);

The workaround is to add a function, which triggers the class generation. Tested with componentize-js version 0.18.2 .

tomasol avatar May 05 '25 18:05 tomasol

Running into the same issue with wasi:graphics-context/graphics-context#abstract-buffer.

It either gives a similar error to the one posted by the OP or sometimes even just hangs indefinitely without any errors.

Adding a simple foo: func(); to the resource gets it to work correctly.

MendyBerger avatar Jun 12 '25 15:06 MendyBerger