无法将“ HTTPS”识别为内部或外部命令

时间:2020-02-24 10:48:29

标签: npm windows-10 command-prompt yarnpkg umijs

我想在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 httpsyarn 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.

5 个答案:

答案 0 :(得分:3)

在Windows上,您需要像“ set HTTPS = true”中那样包含“ set”以设置环境变量。

答案 1 :(得分:3)

只需将以下行添加到.env

HTTPS=true

PORT=8080

HOST=localhost

如果要使用其他主机或端口,请随时用所需的IP地址和端口将localhost替换为任何可用的端口号。如果您没有.env文件,只需在react root文件夹中创建它即可。

此后,您可以运行yarn startnpm 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,此答案可能对您有所帮助。

  1. 第一步:将package.json保留其原始格式,在接下来的步骤中,我们将添加环境变量:

    package.json


  1. 第二步:创建一个设置环境变量的文件:

    enter image description here


  1. 第三步:将环境变量添加到该文件。 set对我不起作用,但是export对我有用:

    enter image description here

注意:默认端口是3000,因此,如果您不在此文件中导出PORT,React将以'https:// localhost:3000'开始


  1. 第四步:source文件。您基本上有2个选择:
    • 选项1:为了仅将这些变量用于当前会话:
      enter image description here

    • 选项2:为了在任何会话中使用这些变量,请将这些行添加到您的~/.bashrc文件中:
      enter image description here


  1. 第五步:运行npm startyarn start,您应该在本地主机上使用https:

    enter image description here

注意:我不是在这里导出端口,只是使用默认端口3000。

答案 4 :(得分:0)

我只是删除 "start": "HTTPS=true react-scripts start", 到 “开始”:“反应脚本开始”, 在 package.json 文件中