我想在Windows(作为Mac的虚拟机)中运行React项目。
在命令提示符下,运行yarn
以安装依赖项。我做了yarn start
。它给了我'HTTPS' is not recognized as an internal or external command
错误。
> yarn start
yarn run v1.13.0
$ HTTPS=true CERT=cert/localhost.crt KEY=cert/localhost.key umi dev
'HTTPS' 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.
有人知道如何解决此问题吗?
编辑1 :
我将节点升级到v12.16.1
(从yarn
升级到1.13.0
,将npm升级到6.13.4
),并升级了yarn add https
和yarn add https-localhost
。但是,yarn start
仍返回'HTTPS' is not recognized as an internal or external command
。
umi dev
返回了'umi' is not recognized as an internal or external command, operable program or batch file.
:
>umi dev
'umi' is not recognized as an internal or external command,
operable program or batch file.
答案 0 :(得分:3)
在Windows上,您需要像“ set HTTPS = true”中那样包含“ set”以设置环境变量。
答案 1 :(得分:3)
只需将以下行添加到.env
:
HTTPS=true
PORT=8080
HOST=localhost
如果要使用其他主机或端口,请随时用所需的IP地址和端口将localhost替换为任何可用的端口号。如果您没有.env
文件,只需在react root文件夹中创建它即可。
此后,您可以运行yarn start
或npm start
,您的项目将使用https而不是http
。
答案 2 :(得分:1)
暂时
代替: “ start”:“ CERT = cert / localhost.crt KEY = cert / localhost.key umi dev react-scripts start”,
仅执行以下操作: “ start”:“反应脚本开始”,
答案 3 :(得分:0)
我在Windows上遇到了同样的问题,但是我使用的是Git Bash,而不是“命令提示符”。 因此,如果您喜欢Git Bash,此答案可能对您有所帮助。
注意:默认端口是3000,因此,如果您不在此文件中导出PORT,React将以'https:// localhost:3000'开始
注意:我不是在这里导出端口,只是使用默认端口3000。
答案 4 :(得分:0)
我只是删除 "start": "HTTPS=true react-scripts start", 到 “开始”:“反应脚本开始”, 在 package.json 文件中