'HTTPS' is not recognized as an internal or external command
Asked Answered
W

8

15

I want to run a React project in my Windows (as a virtual machine of my Mac).

In a Command Prompt, after running yarn to install dependencies. I did yarn start. And it gave me 'HTTPS' is not recognized as an internal or external command error.

> 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.

Does anyone know how to fix this?

Edit 1:

I upgraded node to v12.16.1 (yarn to 1.13.0, npm to 6.13.4), and did yarn add https and yarn add https-localhost. However, yarn start still returned 'HTTPS' is not recognized as an internal or external command.

umi dev returned '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.
Weather answered 24/2, 2020 at 10:48 Comment(12)
you need https package. Install it locally or globally.Inserted
Do you mean SSL Certificate?Weather
no. i mean npm packageInserted
check this: npmjs.com/package/https-localhostInserted
I think it's because of your node version. From a version later, https became a build-in module on node. What is your node version?Peril
node version is 10.15.0Weather
I tried yarn add https-localhost and added the message to OP. After that, yarn start still returned the https error.Weather
Please see my OP, it still did not work...Weather
$ HTTPS=true CERT=cert/localhost.crt KEY=cert/localhost.key umi dev - That looks like a shell command (Bourne/bash/Unix/Linux/POSIX) that invokes the command umi dev after setting variables HTTPS, CERT, and KEY. I'm not familiar with React or Yarn, but could it be it doesn't support Windows, or that something is misconfigured to make it think it's on a Unix-like system?Introit
Make sure you have the following lines in .env file: HTTPS=true PORT=8080 HOST=localhostTiffanitiffanie
You don't need to install any package neither.Tiffanitiffanie
Check also my answer about valid certificate: #41192991Tiffanitiffanie
T
9

Just add the following lines to .env:

HTTPS=true

PORT=8080

HOST=localhost

If you want to use another host or port, feel free to replace localhost with the IP address you want and the port with any available port number. If you don't have .env file, just create it in your react root folder.

After this you can run yarn start or npm start and your project will use https instead of http.

If you need to use a real certificate inatead of a self-signed, then you can take a look at may answer here: How can I provide a SSL certificate with create-react-app?

Tiffanitiffanie answered 20/4, 2020 at 14:4 Comment(1)
If you need to use a real certificate inatead of a self-signed, the you can take a look at may answer here: #41192991Tiffanitiffanie
N
5

On windows you need to include 'set' as in "set HTTPS=true" to set an environment variable.

Numerable answered 20/4, 2020 at 13:26 Comment(0)
I
4

I encountered a similar issue running in a Windows environment, the solution was to include '&&' after setting the environment variables and the command that follows.

Example:

set HTTPS=true set CERT=.cert/localhost.crt set KEY=.cert/localhost.key && umi dev

React Example:

set HTTPS=true set SSL_CRT_FILE=.certificates/localhost.crt set SSL_KEY_FILE=.certificates/localhost.key && react-scripts start
Intestine answered 7/4, 2022 at 5:48 Comment(0)
E
1

For time being

Instead of: "start": "CERT=cert/localhost.crt KEY=cert/localhost.key umi dev react-scripts start",

Do this only: "start": "react-scripts start",

Eburnation answered 15/9, 2020 at 16:44 Comment(0)
S
1

I just had the same problem on Windows but instead of "Command Prompt" I use Git Bash. So if you like Git Bash, this answer might be helpful to you.

  1. Step One: Leave your package.json in its original form, we're going to add the environment variables in the next steps:

    package.json


  1. Step Two: Create a file that will set the environment variables:

    enter image description here


  1. Step Three: Add your environment variables to that file. set didn't work for me but export did:

    enter image description here

Note: The default port is 3000, so if you're not exporting a PORT in this file, React will start at 'https://localhost:3000'


  1. Step Four: source the file. You basically have 2 options:
    • Option 1: In order to use these variables for the current session only:
      enter image description here

    • Option 2: In order to use these variables for any session, add these lines to your ~/.bashrc file:
      enter image description here


  1. Step Five: Run npm start or yarn start and you should be using https on localhost:

    enter image description here

Note: I'm not exporting a PORT here, just using the default port 3000.

Sterling answered 29/9, 2020 at 16:25 Comment(0)
G
1

I just remove "start": "HTTPS=true react-scripts start", to "start": "react-scripts start", in file package.json

Gracia answered 10/6, 2021 at 6:25 Comment(0)
S
0

Just by adding HTTPS=true is enough to make it work.

You can add more to the .env file like the PORT if the post is other than 3000.

Swiger answered 29/6, 2023 at 20:52 Comment(0)
K
0

Make sure you add set before the HTTPS=true. Also, add && after the first command finishes and the react-scripts command starts. This will ensure the proper execution of your command.

The below example worked when I tested it:

set HTTPS=true SSL_CRT_FILE=./certs/cert.crt SSL_KEY_FILE=./certs/cert.key && react-scripts start
Keare answered 1/3 at 3:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.