node.js - React 变量 REACT_APP_API_HOST 不是内部或外部命令
问题描述
我是 React 项目的初学者并尝试使用运行项目,yarn start
但出现此错误:
D:\Projects\Demo>yarn start
yarn run v1.7.0
$ REACT_APP_API_HOST=https://us-central1-mydemo.cloudfunctions.net/ react-s
cripts start
'REACT_APP_API_HOST' is not recognized as an internal or external command,
operable program or batch file.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
这就是 package.json 中的内容:
"scripts": {
"start": "REACT_APP_API_HOST=https://us-central1-mydemo.cloudfunctions.net/ react-scripts start"
}
如何修复此错误?任何帮助表示赞赏。
解决方案
如果您使用的是 Windows,则在环境变量方面可能会令人窒息。我建议获取跨环境包(https://www.npmjs.com/package/cross-env)并将您的启动脚本更改为:
"scripts": {
"start": "cross-env REACT_APP_API_HOST=https://us-central1-mydemo.cloudfunctions.net/ react-scripts start"
}
推荐阅读
- python - 在 Kedro 中等待节点完成
- mysql - 使用节点js显示来自mysql的数据时未定义数据
- python - Pygame 窗口在几秒钟后一直冻结
- visual-studio-extensions - 如何在源代码管理下存储所需扩展的列表?
- spring-boot - Spring Boot 微服务中的会话管理
- linux - Linux一更改就保存文件
- reactjs - 有没有办法检查屏幕是否在底部标签导航中 - 反应导航 5.X
- wolfram-mathematica - 对变量有共同限制的并行 FindFit
- node.js - 将协商身份验证传递给 IIS 站点
- python - BS4 通过抓取表格给出一个奇怪的随机输出