How to convert raw .wasm file text to a TypedArray whose buffer is compatible with instantiate()?

I’m fetching a .wasm file and converting that file to a Uint8Array using TextEncoder encode().

Unfortunately the buffer of the Uint8Array when passed to WebAssembly.instantiate() throws

fetch("/path/to/file.wasm")
  .then((r) => r.text())
  .then((text) => {
    return new TextEncoder().encode(text)
  })
  .then((uint8) => {
      console.log(WebAssembly.validate(uint8));
      WebAssembly.instantiate(uint8.buffer, 
  // ...

CompileError: WebAssembly.instantiate(): section (code 1, “Type”) extends past end of the module (length 7299055, remaining bytes 166825) @+8

In this case I can’t use instantiateStreaming() because the context I’m running the WebAssembly module in does not expose fetch() or Response.

What I’m working on doing is writing the .wasm file as an array [...] in the script dynamically that will be run in the context that doesn’t support fetch() or Response(), pass the array to a TypedArray then pass the buffer from the TypedArray to instantiate().

How to convert raw .wasm file text to a TypedArray whose buffer is compatible with instantiate()?