0
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?

【Nextjs】.envに設定したURLが読み込まれないエラーの解決方法について

Posted at

はじめに

Nextjsでアプリ開発中本番環境のURLが読み込まれていないエラーが表示され、そちらの解決方法について記事にします。


【修正前のコード】

.env
API_URL= xxxxxxxxxx
.tsx
const API_URL = process.env.API_URL || "http://localhost:8787";

解決方法

NEXT_PUBLIC_を使用する

.env
NEXT_PUBLIC_API_URL= xxxxxxxxxx
.tsx
const API_URL = process.env.NEXT_PUBLIC_API_URL || "http://localhost:8787";

参考

おわりに

今までNEXT_PUBLIC_の意味を理解せず使用しておりました。
勉強になりました。


JISOUのメンバー募集中!

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

0
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
0
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?