gluon-lang / gluon

A static, type inferred and embeddable language written in Rust.
https://gluon-lang.org
MIT License
3.16k stars 145 forks source link

Runtime error on WASM #941

Open Boscop opened 1 year ago

Boscop commented 1 year ago

When I try to use gluon on Wasm (in a web frontend using trunk serve), I get this runtime error:

Uncaught TypeError: Failed to resolve module specifier "env". Relative references must start with either "/", "./", or "../".

I'm using the latest version with these features:

gluon = { git = "https://github.com/gluon-lang/gluon", default-features = false, features = ["random"] }
gluon_codegen = { git = "https://github.com/gluon-lang/gluon" }

(When I don't call the function that uses gluon, the frontend works fine without errors.)

Any idea why it's not working? :)

Boscop commented 1 year ago

Btw, a related question: How can I add gluon modules that should be are available for import, such that I specify them as string (.glu file content + module name), not as real filename? In my use case the modules only exist as Strings in RAM (e.g. when running in the Wasm frontend), not as files on the file system. So I'd like to import them from RAM, is it possible somehow? :)

Marwes commented 1 year ago

Calling load_script will register the script under the given file name which you can then import by refering to the module name (my/file.glu -> my.file etc)

Marwes commented 1 year ago

No idea why WASM isn't working, never tested it throughly so something may have broken.