By nadmaha3475
Hi First of all thanks for the informative post made and it was really helpful for me as a newbie for react and typescript. This could be a silly question that as I gone through the tutorial (https://www.digitalocean.com/community/tutorials/how-to-build-a-customer-list-management-app-with-react-and-typescript) and while trying to run the program it came a issue that “Cannot find module ‘./serviceWorker’ or its corresponding type declarations” in typescript-react-app/src/index.tsx, I struggle a lot to find a solution yet not succeed. Can you help me on this point. Following are the complete error message.
D:/UserData/reactPractice/reactApp4/typescript-react-app/src/index.tsx TypeScript error in D:/UserData/reactPractice/reactApp4/typescript-react-app/src/index.tsx(6,32): Cannot find module ‘./serviceWorker’ or its corresponding type declarations. TS2307
4 | import App from './App';
5 | import { BrowserRouter } from 'react-router-dom';
6 | import * as serviceWorker from ‘./serviceWorker’; | ^ 7 | ReactDOM.render( 8 | <BrowserRouter> 9 | <App />
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Heya,
Just came across this answer and decided to write some general guidelines for anyone who comes across this in the future despite the old question.
The error you’re seeing suggests that TypeScript can’t locate a module named serviceWorker in your project. This often happens when the serviceWorker.ts file is missing from your project directory or if the import path specified in index.tsx is incorrect.
In Create React App versions 4 and onward, a file named service-worker.ts is present instead of serviceWorker.ts. If you’re using this version or above, you should change your import statement to: import * as serviceWorker from ‘./service-worker’;
Otherwise, if you’re following the tutorial strictly and you don’t want to use a service worker, you can remove that import line completely.
Hope that this helps!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.