【问题标题】:property '_env_' does not exist on type 'Window & typeof globalThis - React / Typescript ERROR属性 '_env_' 在类型'Window & typeof globalThis 上不存在 - React / Typescript 错误
【发布时间】:2022-01-04 14:41:39
【问题描述】:

我收到此错误,我正在使用 React/TypeScript

当我这样做时,在组件中。

<p>API_URL: {window._env_.API_URL}</p>

我收到此错误:

property '_env_' does not exist on type 'Window & typeof globalThis

关注这个:https://www.freecodecamp.org/news/how-to-implement-runtime-environment-variables-with-create-react-app-docker-and-nginx-7f9d42a91d70/

【问题讨论】:

标签: javascript reactjs typescript


【解决方案1】:

你必须使用前缀 (REACT_APP) 并且在访问 env 文件之后,你必须使用 proccess

<p>API_URL: {process.env.REACT_APP_API_URL}</p>

【讨论】:

  • 我以前见过这种情况,尽管这更多地与 Typescript 错误有关。窗户类型
猜你喜欢
  • 2021-09-10
  • 2022-06-14
  • 2021-05-13
  • 2022-08-05
  • 2021-04-09
  • 2021-09-20
  • 2020-12-23
  • 2021-12-07
  • 2019-10-20
相关资源
最近更新 更多