问题描述
在 package.json
中的 Firefly示例项目中
"start": "sh -ac '. ./.env.dev; firebase use dev && react-scripts start'",
在我的Windows 10上,它不能与&&
一起使用:
On my Windows 10 its not working with &&
:
此脚本使用;
而不是&&
进行操作,应用启动,但无法连接数据库:
This script works with ;
instead of &&
, App starts, but it doesn't connect fo database:
@firebase/firestore: Firestore (5.0.4): Could not reach Cloud Firestore backend. Connection failed 2 times. Most recent error: FirebaseError: [code=not-found]: The project firefly-boilerplate
does not exist or it does not contain an active Cloud Datastore database.
因此,我必须将 .env.dev
中的Api密钥,域和项目名称放入 index.js
中才能正常工作.为什么此脚本不适用于&&
?
So I must put Api key, domain, and project name from .env.dev
into index.js
to work. Why this script doesn't work with &&
?
sh -ac
命令的作用是什么?
推荐答案
sh
是用于运行shell的POSIX命令(shell是为命令行终端供电的程序).运行 sh -ac
的意思是运行shell命令并自动导出运行期间分配的所有变量".
sh
is the POSIX command for running a shell (a shell is the program that powers the command-line terminal). Running sh -ac
is saying "run the shell command and automatically export all variables assigned during its run" effectively.
.env
文件通常用于描述脚本运行所需的本地环境变量,因此 sh -ac ./.env.dev
基本上是说从 .env.dev
加载所有环境变量.
A .env
file is often used to describe local environment variables needed for scripts to run, so sh -ac ./.env.dev
is basically saying load all the environment variables from .env.dev
.
然后通过&&
在随后的命令中使用这些环境变量,该代码在单个上下文中执行多个命令.
Those environment variables are then made available in the subsequent commands via &&
which executes multiple commands in a single context.
简单来说,该脚本不是Windows友好的.您想要做的是在 .env.dev
中查看它所设置的环境变量,然后在运行 firebase
和反应脚本命令.
This script is, simply speaking, not very Windows-friendly. What you would want to do is take a look inside .env.dev
at the environment variables it's setting and then set those in your local terminal before running the firebase
and react-scripts
commands.
这篇关于Package.json带有"sh -ac"的复杂启动脚本;和.env文件用于Firebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!