React app error: Failed to construct 'WebSocket': An insecure WebSocket connection may not be initiated from a page loaded over HTTPS

后端 未结 8 1579
南方客
南方客 2020-12-01 10:29

I am deploying a React app but am getting a strange error when I visit the page over https.

When I visit the page over https I receive the following error:

S

8条回答
  •  栀梦
    栀梦 (楼主)
    2020-12-01 11:00

    For folks waiting for react-scripts for a patch:

    For local testing over https, you can manually edit

    node_modules/react-dev-utils/webpackHotDevClient.js
    

    Here's the code you'll want at line 62 of that file:

    protocol: window.location.protocol === 'https:' ? 'wss' : 'ws',
    
    

    For deployment follow below steps:

    npm install -g serve // This can be done locally too
    
    npm run build
    
    

    And Then in your package.json add a deploy script to work with serve:

    "scripts": {
        "deploy": "serve -s build",
    }
    

    And then

    npm deploy or yarn deploy

    Hope this answer helps you get rid of the error.

    For more info refer to here`

    This bug has been fixed in the latest version of the release. Click here to see the source file

提交回复
热议问题