kwonoj/cld3-asm

environment detection error on webworker

Closed this issue · 5 comments

hixus commented

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

  • npm install
  • npm run dev-build
  • npm run dev-server (in another terminal)
  • with postman or curl query localhost:3000
  • produces 500 error and in the dev-build terminal shows "Error: environment detection error"

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.

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

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.

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.

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.