Unhandled Rejection (SecurityError): The operation is insecure. On a fresh create-react-app project

后端 未结 5 2402
孤街浪徒
孤街浪徒 2021-02-19 15:26

I created a new project with create-react-app then ran npm start then this showed up. https://imgur.com/a/3By9NCr

Using FF 69.0.3

相关标签:
5条回答
  • 2021-02-19 15:28

    I had this error occur as well. Was able to clear it up by deleting the create-react-app serviceWorker.js file

    0 讨论(0)
  • 2021-02-19 15:31

    A lot of answers here do actually solve the issue but the simplest way I have found is to add npm package serve to your dependencies.

    yarn add serve or npm i serve

    and then replace your start script with the following:

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

    This is actually straight out of the create-react-app docs

    0 讨论(0)
  • 2021-02-19 15:43

    Another solution found in the link in the answer by Niraj Niroula:

    If you want to keep the Delete cookies and site data when Firefox is closed option enabled, click on the Manage Exceptions button and add localhost (with the protocol and port) to the exceptions list:

    0 讨论(0)
  • 2021-02-19 15:45

    This problem seems to only happen in Firefox. Edge worked fine.

    After creating the project, in index.js change:

    serviceWorker.register();
    //serviceWorker.unregister();
    

    Still trying to figure whose fault this is, but this should get you going.

    0 讨论(0)
  • 2021-02-19 15:48

    Seems that the issue exists only in Firefox. Anyone still bugged by this bug can try disabling Delete cookies and site data when Firefox is closed option in Privacy and Security settings. Or try wrapping the navigator.serviceWorker usages inside a try/catch. In my case

      if ("serviceWorker" in navigator) {
        navigator.serviceWorker.ready
          .then(registration => {
            registration.unregister();
          })
          .catch(error => console.log("ServiceWorker Warning: ", error));
      }
    

    For related discussion and more info

    0 讨论(0)
提交回复
热议问题