Minh Chu
Minh Chu

Reputation: 289

Cannot set env with create-react-app

I use create-react-app with react-script version 1.0.7, node 6.10.2

In my project root, I create .env:

API_ENDPOINT=https://dev-api.com

And in src/common/api.js, I have:

import axios from 'axios';

const apiEndpoint = process.env.API_ENDPOINT;
axios.defaults.baseURL = apiEndpoint || 'https://prod-api.com';

After building the project with yarn run build, I check the api call from browser console and it always is https://prod-api.com.

Do you have any ideas. Thanks

Upvotes: 0

Views: 871

Answers (1)

Minh Chu
Minh Chu

Reputation: 289

I just read the docs again. Environment variable should start with REACT_APP_:

By default you will have NODE_ENV defined for you, and any other environment variables starting with REACT_APP_

Upvotes: 1

Related Questions