Umi: process.env return undefined

Created on 26 Aug 2020  ·  9Comments  ·  Source: umijs/umi

process.env return undefined

I use Ant Design Pro v4. After update umi version, env variables are returned undefined.

Context

  • Ant Design Pro: 4
  • Umi Version: 3.2.17
  • Node Version: 2.16.1
Need Reproduce

Most helpful comment

If you want to use REACT_APP_API, set the define in config file.

export default {
  define: {
    'process.env.REACT_APP_API': process.env.REACT_APP_API,
  }
}

All 9 comments

@xiaohuoni When will you solve this problem?

I have the same issue. Any help with this would be appreciated @xiaohuoni

How to reproduce it?

@sorrycc how to reproduce it?

Why use process.env? process.env.NODE_ENV should have defined.

@sorrycc I defined variables in .env file. But i cant reach these variables in js after update umijs.

api.js
const {REACT_APP_API } = process.env;
return callApi(${REACT_APP_API}/auth/token, { method: 'GET', });

.env
REACT_APP_API=https://blabla.com

@sorrycc ,

I Have Same Problem .
How can get .env file variables with process.env ?

@mohaphez @DanielFromTAFE @xiaohuoni use UMI_APP_* prefix instead of REACT_APP_* for env vars. I used that and worked!

For Example: REACT_APP_API ---- > UMI_APP_API

If you want to use REACT_APP_API, set the define in config file.

export default {
  define: {
    'process.env.REACT_APP_API': process.env.REACT_APP_API,
  }
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ohmygod481999 picture ohmygod481999  ·  19Comments

masonzhang picture masonzhang  ·  22Comments

wenj91 picture wenj91  ·  19Comments

MinJieLiu picture MinJieLiu  ·  20Comments

clock157 picture clock157  ·  41Comments