r-wasm / webr

The statistical language R compiled to WebAssembly via Emscripten, for use in web browsers and Node.
https://docs.r-wasm.org/webr/latest/
Other
804 stars 54 forks source link

uuid fails in webR #406

Closed timelyportfolio closed 2 months ago

timelyportfolio commented 2 months ago

Thanks so much for your continued efforts on webr. I absolutely love pushing its limits and exploring its magical capabilities. I noticed an error that now happens in 0.3.1 with some of my old code using the officer package that worked previously. I have traced to uuid::UUIDgenerate(), and pasted the error text below. I in no way expect you to be able to support all packages and only am creating this issue in case it is helpful. If out of scope or not interesting, please feel free to close the issue and focus on all the other amazing work you are doing.

Code to replicate:

library(uuid)
uuid::UUIDgenerate()

Console error:

R.bin.js:1861 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'apply')
    at stubs.<computed> (R.bin.js:1861:118001)
    at 0001092a:0x296a
    at 0001092a:0x1a5c
    at 0001092a:0x1af9
    at 0001092a:0xa64
    at R.bin.wasm:0x147d1a
    at R.bin.wasm:0x14ac22
    at R.bin.wasm:0x1660d1
    at R.bin.wasm:0x166ec9
    at R.bin.wasm:0x166a3a
stubs.<computed> @ R.bin.js:1861
$ul_random_get_bytes @ 0001092a:0x296a
$__uuid_generate_random @ 0001092a:0x1a5c
$uuid_generate @ 0001092a:0x1af9
$UUID_gen @ 0001092a:0xa64
$func998 @ R.bin.wasm:0x147d1a
$func999 @ R.bin.wasm:0x14ac22
$Rf_eval @ R.bin.wasm:0x1660d1
$func1386 @ R.bin.wasm:0x166ec9
$Rf_applyClosure @ R.bin.wasm:0x166a3a
$Rf_eval @ R.bin.wasm:0x16615d
$Rf_ReplIteration @ R.bin.wasm:0x184cfe
$func1707 @ R.bin.wasm:0x18b66c
$run_Rmainloop @ R.bin.wasm:0x18b59c
$Rf_mainloop @ R.bin.wasm:0x18b69a
$__main_argc_argv @ R.bin.wasm:0xfefbd
callMain @ R.bin.js:1861
run @ webr-worker.js:2631
Module2.onRuntimeInitialized @ webr-worker.js:5039
doRun @ R.bin.js:1861
run @ R.bin.js:1861
runCaller @ R.bin.js:1861
removeRunDependency @ R.bin.js:1861
(anonymous) @ R.bin.js:1861
Promise.then (async)
loadDylibs @ R.bin.js:1861
receiveInstance @ R.bin.js:1861
receiveInstantiationResult @ R.bin.js:1861
Promise.then (async)
(anonymous) @ R.bin.js:1861
Promise.then (async)
instantiateAsync @ R.bin.js:1861
createWasm @ R.bin.js:1861
(anonymous) @ R.bin.js:1861
loadScript @ webr-worker.js:1974
(anonymous) @ webr-worker.js:5101
setTimeout (async)
init @ webr-worker.js:5099
onWorkerMessage @ webr-worker.js:4358
globalThis.onmessage @ webr-worker.js:4369
georgestagg commented 2 months ago

Thanks for reporting this. It looks like uuid::UUIDgenerate() has failed with the same issue as far back as v0.2.0.

See https://github.com/r-wasm/rwasm/pull/32 for details of what is going wrong. I've pushed an update to the webR package repository using the contents of this PR, which should help (at least on v0.3.1, /latest...)

Screenshot 2024-04-08 at 09 24 16

Please let me know if this fixes your officer issue too.

timelyportfolio commented 2 months ago

@georgestagg wow, thanks so much for the very quick response, and it works brilliantly. I hope this was in some way helpful beyond just this issue. Now off to work on a presentation featuring webr.