Skip to content

Running in Chrome/Node.js - am I doing something wrong? #163

@drogus

Description

@drogus

Hi, it's a very cool project! I'm trying to run an example code:

function init() {
  let message: string = 'Hello, World!';

  function test() {
    console.log(message);
  }

  test()
}

export { init };
export default init;

I compiled it with:

node cli/ts2wasm.js --opt=3 example.ts -o out.wasm --debug --sourceMap

I'm trying to run in Chrome or in Node.js according to instructions and in both cases the result is simply a null value printed in console.log. I also tried just console.log("a string literal"); and there is still no output, so I'm guessing it's something with the environment? This is the command I'm using to run it:

node --experimental-wasm-gc --experimental-wasm-stringref run_module.js -f init out.wasm

I've tried on Node v23 and also a build from Git.

The generated WASM is:

    call $global|init|func
    i32.const 1144
    i32.const 13
    string.new_utf8
    drop
    ref.null none
    ref.null none
    global.get $dyntype_context
    i32.const 1160
    i32.const 4
    string.new_utf8
    call $dyntype_new_string
    array.new_fixed $array0 1
    i32.const 1
    struct.new $array-struct0
    call $builtin|Console|log

Now I don't know much about libdyntype, but it looks correct. The call to test() got optimized, so it's just creating a new string, pushing it to an arguments array and calling Console.log.

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