Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module not found: Can't resolve './registerServiceWorker

I'm having truoble when I'm trying to compile my react application. When I'm compilie the application I'm recieveing the following error: Module not found: Can't resolve './registerServiceWorker

This is my index.js file:

import React from 'react';
import ReactDOM from 'react-dom';
import ApolloClient from "apollo-boost"
import {ApolloProvider} from "react-apollo"
import App from './App';
import registerServiceWorker from './registerServiceWorker';

const client = new ApolloClient({
   uri: "http://localhost:4000"
});

ReactDOM.render(
<ApolloProvider client={client}>
    <App />
    </ApolloProvider>,
    document.getElementById('root')
    );
registerServiceWorker();

I've used create-react-app, and I removed some not used files:

App.test.js
App.css
index.css
logo.svg

I think that this is the cause of the issue, but I can't locate the source of this issue.

Thanks in advance!

like image 953
Ido Segal Avatar asked Dec 08 '18 17:12

Ido Segal


People also ask

What is registerServiceWorker in React?

The service worker is a web API that helps you cache your assets and other files so that when the user is offline or on slow network, he/she can still see results on the screen, as such, it helps you build a better user experience, that's what you should know about service worker's for now.


1 Answers

I think the module should be called serviceWorker, not registerServiceWorker, although this depends on which version of CRA you used. The most recent version uses:

import * as serviceWorker from './serviceWorker';

and then

serviceWorker.unregister();

like image 156
Colin Ricardo Avatar answered Sep 21 '22 16:09

Colin Ricardo