fe797c1074
Internal suggestion to remove `en-US` from Mozilla urls since MDN is available in multiple languages nowadays it will automatically redirect to the viewer’s language preference. Closes [DX-2076](https://linear.app/vercel/issue/DX-2076/make-external-mozilla-links-language-agnostic-in-nextjs-docs)
29 lines
897 B
Text
29 lines
897 B
Text
---
|
|
title: Dynamic WASM compilation is not available in Middlewares
|
|
---
|
|
|
|
## Why This Error Occurred
|
|
|
|
Compiling WASM binaries dynamically is not allowed in Middlewares. Specifically,
|
|
the following APIs are not supported:
|
|
|
|
- `WebAssembly.compile`
|
|
- `WebAssembly.instantiate` with [a buffer parameter](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate#primary_overload_%E2%80%94_taking_wasm_binary_code)
|
|
|
|
## Possible Ways to Fix It
|
|
|
|
Bundle your WASM binaries using `import`:
|
|
|
|
```ts filename="middleware.ts"
|
|
import { NextResponse } from 'next/server'
|
|
import squareWasm from './square.wasm?module'
|
|
|
|
export default async function middleware() {
|
|
const m = await WebAssembly.instantiate(squareWasm)
|
|
const answer = m.exports.square(9)
|
|
const response = NextResponse.next()
|
|
|
|
response.headers.set('x-square', answer.toString())
|
|
return response
|
|
}
|
|
```
|