- Turbopack の壁が立ちはだかり、無事敗北
- そもそも
node:testをアプリケーションコードで使ってはならない - モンキーパッチも極力避けるべき
- モンキーパッチするよりは https://www.npmjs.com/package/patch-package や yarn patch, pnpm patch を使うほうがマシ
- 大人しく vercel/next.js#49302 の解決を待ちましょう
Last active
March 3, 2026 16:31
-
-
Save mizdra/b0537e418cbb1072e137fa61c33994b8 to your computer and use it in GitHub Desktop.
どうしても Next.js で Server Function から 400 を返したい者の悪あがき
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "use server"; | |
| import { mock } from 'node:test'; | |
| const httpAccessFallbackModule = await import("next/dist/client/components/http-access-fallback/http-access-fallback.js"); | |
| // ref: https://github.com/vercel/next.js/blob/6f763ecfd48acc3593f8a10328aef9358fdb7c75/packages/next/src/client/components/http-access-fallback/http-access-fallback.ts | |
| mock.module('next/dist/client/components/http-access-fallback/http-access-fallback.js', { | |
| namedExports: { | |
| ...httpAccessFallbackModule, | |
| isHTTPAccessFallbackError: (error: unknown): error is any => { | |
| if ( | |
| typeof error !== 'object' || | |
| error === null || | |
| !('digest' in error) || | |
| typeof error.digest !== 'string' | |
| ) { | |
| return false | |
| } | |
| const [prefix] = error.digest.split(';'); | |
| return ( | |
| prefix === httpAccessFallbackModule.HTTP_ERROR_FALLBACK_ERROR_CODE | |
| ); | |
| }, | |
| }, | |
| }); | |
| function badRequest(): never { | |
| const digest = `${httpAccessFallbackModule.HTTP_ERROR_FALLBACK_ERROR_CODE};400`; | |
| const error = new Error(digest); | |
| // @ts-expect-error | |
| error.digest = digest; | |
| throw error; | |
| } | |
| export async function greet(name: string): Promise<string> { | |
| badRequest(); | |
| return `Hello, ${name}!`; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
