1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【React / Next.js】 Error: can only be run inside the edge runtime の解決方法について

Last updated at Posted at 2025-05-14

はじめに

udemyのNext.jsハンズオンでデータベースから情報を取得する実装をしたところで下記のようなエラーに遭遇しましたので、こちらの解決方法について記事にします。
前提条件として、ハンズオンではSupabaseによるAPIでのデータを取得しておりますが、今回CloudflareのD1で試みております。

エラー内容

Error: getRequestContext and getOptionalRequestContext can only be run
inside the edge runtime, so please make sure to have included
export const runtime = 'edge' in all the routes using such functions

翻訳すると以下の内容のようでした。
エラー: getRequestContextgetOptionalRequestContext は Edge ランタイム内でのみ実行できます。そのため、これらの関数を使用するすべてのルートに export const runtime = 'edge' が含まれていることを確認してください

CloudfrareのD1などを使う時はEdge Runtimeで動かす必要があるようです。

こちらをapiディレクトリファイルに追加

.ts
export const runtime = 'edge';

参考

おわりに

これでとりあえずエラーは解決することができました。

JISOUのメンバー募集中!

プログラミングコーチングJISOUでは、新たなメンバーを募集しています。
日本一のアウトプットコミュニティでキャリアアップしませんか?
興味のある方は、ぜひホームページをのぞいてみてください!
▼▼▼

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?