Skip to content

Latest commit

 

History

History
29 lines (21 loc) · 897 Bytes

middleware-dynamic-wasm-compilation.mdx

File metadata and controls

29 lines (21 loc) · 897 Bytes
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:

Possible Ways to Fix It

Bundle your WASM binaries using import:

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
}