LoginSignup
92
34

More than 3 years have passed since last update.

create-react-appのプロジェクトで環境変数を.envから読み込めない原因と解決策

Last updated at Posted at 2019-01-09

はじめに

create-react-appで作成したプロジェクトで.envから環境変数を読み込めないときは下記のTipsを確認してみてください。

  • Viewが多いのでまとめ直しました。(2020/05/05)

.envを読み込めなかった原因と解決策

1. .envを設定後にコンパイルしていない

  • .envに環境変数を書き込んだ後は一度Ctrl +Cで終了した後に、npm startで再コンパイルしましょう。

2. 環境変数のKEYがREACT_APP_から始まっていない

.env
REACT_APP_APP_ID="YOUR_APP_ID"

3. .envがプロジェクト直下に作成されていない

  • node_modulesなどが配置されているrootディレクトリに.envを作成する必要があります。
.
├── .env
├── .eslintrc
├── .git
├── .gitignore
├── .node-version
├── .prettierrc
├── .storybook
├── README.md
├── build
├── node_modules
├── package-lock.json
├── package.json
├── paths.json
├── public
├── src
├── tsconfig.json
└── yarn.lock

92
34
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
92
34