In addition to TypeScript and JavaScript, the following module types are automatically configured to be importable in your Worker code.
| Module extension | Imported type |
|---|---|
.txt | string |
.html | string |
.sql | string |
.bin | ArrayBuffer |
.wasm,.wasm?module | WebAssembly.Module |
For example, with the following import,text will be a string containing the contents ofexample.txt:
importtext from"./example.txt";This is also the basis for importing Wasm, as in the following example:
importwasm from"./example.wasm";// Instantiate Wasm modules in the module scopeconstinstance=awaitWebAssembly.instantiate(wasm);exportdefault{fetch(){constresult=instance.exports.exported_func();returnnewResponse(result);},};Cloudflare Workers does not supportWebAssembly.instantiateStreaming().