title: [React.js]Attempted import error: './registerServiceWorker' does not contain a default export (imported as 'registerServiceWorker')
body: <p>I am trying to create a react app fetching pokemon API, but I've encountered the following issue that says Attempted import error: './registerServiceWorker' does not contain a default export (imported as 'registerServiceWorker'). but I do have a <code>export default App;</code> in my App.js file, here's my following content, not too sure what is the issue, help will be massively appreciated.</p>
  
  <p>App.js</p>
  
  <pre><code>import React, { Component } from 'react';
  import './styles/App.css';
  
  
  class App extends Component {
    render() {
      return (
        &lt;div className="App"&gt;
          hellohello
        &lt;/div&gt;
      );
    }
  }
  
  
  export default App;
  
  </code></pre>
  
  <pre><code>import React from 'react';
  import ReactDOM from 'react-dom';
  import './index.css';
  import App from './components/App';
  import registerServiceWorker from './registerServiceWorker';
  
  ReactDOM.render(&lt;App /&gt;, document.getElementById('root'));
  registerServiceWorker();
  
  </code></pre>
  
  <pre><code>
  
  const isLocalhost = Boolean(
    window.location.hostname === 'localhost' ||
      // [::1] is the IPv6 localhost address.
      window.location.hostname === '[::1]' ||
      // 127.0.0.0/8 are considered localhost for IPv4.
      window.location.hostname.match(
        /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
      )
  );
  
  export function register(config) {
    if (process.env.NODE_ENV === 'production' &amp;&amp; 'serviceWorker' in navigator) {
  
      const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
      if (publicUrl.origin !== window.location.origin) {
  
        return;
      }
  
      window.addEventListener('load', () =&gt; {
        const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
  
        if (isLocalhost) {
          checkValidServiceWorker(swUrl, config);
  
  
          navigator.serviceWorker.ready.then(() =&gt; {
            console.log(
              'This web app is being served cache-first by a service ' +
                'worker.'
            );
          });
        } else {
          registerValidSW(swUrl, config);
        }
      });
    }
  }
  
  function registerValidSW(swUrl, config) {
    navigator.serviceWorker
      .register(swUrl)
      .then(registration =&gt; {
        registration.onupdatefound = () =&gt; {
          const installingWorker = registration.installing;
          if (installingWorker == null) {
            return;
          }
          installingWorker.onstatechange = () =&gt; {
            if (installingWorker.state === 'installed') {
              if (navigator.serviceWorker.controller) {
  
                console.log(
                  'New content is available and will be used when all ' +
                    'tabs for this page are closed.'
                );
  
  
                if (config &amp;&amp; config.onUpdate) {
                  config.onUpdate(registration);
                }
              } else {
  
                console.log('Content is cached for offline use.');
  
  
                if (config &amp;&amp; config.onSuccess) {
                  config.onSuccess(registration);
                }
              }
            }
          };
        };
      })
      .catch(error =&gt; {
        console.error('Error during service worker registration:', error);
      });
  }
  
  function checkValidServiceWorker(swUrl, config) {
    fetch(swUrl, {
      headers: { 'Service-Worker': 'script' }
    })
      .then(response =&gt; {
        const contentType = response.headers.get('content-type');
        if (
          response.status === 404 ||
          (contentType != null &amp;&amp; contentType.indexOf('javascript') === -1)
        ) {
          navigator.serviceWorker.ready.then(registration =&gt; {
            registration.unregister().then(() =&gt; {
              window.location.reload();
            });
          });
        } else {
          registerValidSW(swUrl, config);
        }
      })
      .catch(() =&gt; {
        console.log(
          'No internet connection found. App is running in offline mode.'
        );
      });
  }
  
  export function unregister() {
    if ('serviceWorker' in navigator) {
      navigator.serviceWorker.ready.then(registration =&gt; {
        registration.unregister();
      });
    }
  }
  
  </code></pre>