kwonoj / cld3-asm

WebAssembly based Javascript bindings for google Compact Language Detector v3
MIT License
56 stars 7 forks source link

environment detection error on webworker #135

Closed hixus closed 5 years ago

hixus commented 5 years ago

I'm trying to run this module as cloudflare worker. However I get "Error: environment detection error". I think this is because cloudflare workers don't implement "importScripts"

I'm quite new to workers and webassembly so not sure if this just is configuration problem in my end. However what i read from webpack produced code there was a check: "Module.ENVIRONMENT has been deprecated. To force the environment, use the ENVIRONMENT compile-time option (for example, -s ENVIRONMENT=web or -s ENVIRONMENT=node)" And also found commit related to environment detection

I created example repo for reproducing the issue.

Just run

kwonoj commented 5 years ago

It's likely due to limited by environment doesn't implement fully as same as normal worker thread does. Latest cld3-asm doesn't have any env override but browser side bundle already supports worker thread, so you shouldn't need (and not supported anyway) to try set env. Clarifying, broswer side bundle specified -s ENV=broswer,worker compile time.

I'm bit unsure if it's possible to make it work on given cloudflare worker environment if it doesn't fully support worker's interfaces emscripten uses.

kwonoj commented 5 years ago

My suggestion is try any minimal hello world wasm with emscripten to verify cloudflare worker doesn't support it really - then this should be supported by cloudflare.

hixus commented 5 years ago

Ok thanks. I'm little bit confused as with cloudflare workes it seems that you need to upload wasm files separately and then use "new WebAssembly.Instance(MY_WASM_MODULE, imports)". However I don't see any wasm-files that cld3-asm produces.

kwonoj commented 5 years ago

Yes, that's not supported case of cld-3asm out of box. If you'd like to use raw wasm binary, you may need build binary using https://github.com/kwonoj/docker-cld3-wasm which cld3-asm also relies on.

kwonoj commented 5 years ago

Let me close issue for now cause main target of cld3-asm is node / browser (and worker), don't have immediate plan to separate binaries.