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?

More than 3 years have passed since last update.

環境変数が読み込めない【Next.js】

Last updated at Posted at 2021-03-16

問題

Next.jsを用いたプロジェクト内で以下のように環境変数を参照しようとしても参照できない(特にエラーメッセージなし)

.env
VAL=sample
// 環境変数VALを表示
console.log(process.env.VAL);

解決方法

変数名をNEXT_PUBLIC_~としていないのが原因でした。

VALNEXT_PUBLIC_VALと変更すると解決できました。

詳細はこちら

.env
NEXT_PUBLIC_VAL=sample
// 環境変数VALを表示
console.log(process.env.NEXT_PUBLIC_VAL);
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?