mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
71ce95dffa
> [!NOTE] > Best reviewed by each commit for better diff view. This PR clones the Middleware docs for Proxy and removes the Middleware docs. Did not clone the list of docs: - `errors/middleware-upgrade.mdx` - It's a middleware upgrade guide from v12.2 - `errors/beta-middleware.mdx` - It's an error when using middleware before v12.2 - `errors/returning-response-body.mdx` - Legacy behavior from versions < v12.2
30 lines
879 B
Plaintext
30 lines
879 B
Plaintext
---
|
|
title: Dynamic WASM compilation is not available in Proxies
|
|
---
|
|
|
|
## Why This Error Occurred
|
|
|
|
Compiling WASM binaries dynamically is not allowed in Proxies. 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="proxy.ts"
|
|
import { NextResponse } from 'next/server'
|
|
import squareWasm from './square.wasm?module'
|
|
|
|
export default async function proxy() {
|
|
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
|
|
}
|
|
```
|