最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Unable to compile react application as it says "Module not found" - Stack Overflow

programmeradmin5浏览0评论

I have been trying to execute a very simple react application, but for some reason I'm unable to pile it. When i try to pile it in bash using "npm start", i get the error stating "Failed to pile: ./src/index.js Module not found: Can't resolve './registerServiceWorker' in '/Users/Pruthvi/Desktop/ReactApplication/my-app/src'"

can anybody help me as I am a new bee to react application!

I have been trying to execute a very simple react application, but for some reason I'm unable to pile it. When i try to pile it in bash using "npm start", i get the error stating "Failed to pile: ./src/index.js Module not found: Can't resolve './registerServiceWorker' in '/Users/Pruthvi/Desktop/ReactApplication/my-app/src'"

can anybody help me as I am a new bee to react application!

Share Improve this question edited Dec 22, 2017 at 3:05 Jules Dupont 7,5777 gold badges42 silver badges41 bronze badges asked Dec 21, 2017 at 23:09 dmesgdmesg 1011 gold badge1 silver badge8 bronze badges 2
  • 1 You are using create-react-app, right? Did you delete or modify any of the files create-react-app automatically created when you made the project? – Jules Dupont Commented Dec 21, 2017 at 23:17
  • Yes, I deleted few files which are not required for me to work with. I’m referring a tutorial and I have implemented exactly what was shown. But for some reason, I’m unable to proceed and catch up with the tutorial because of this. – dmesg Commented Dec 22, 2017 at 1:04
Add a ment  | 

2 Answers 2

Reset to default 12

By default, create-react-app will create a progressive web app, as documented here. The progressive web app relies on registerServiceWorker() in the registerServiceWorker.js file. You have apparently deleted this file, so your project no longer builds.

You have two choices:

  1. Keep your project as a progressive web app, in which case you should simply restore the original state you had after first creating.
  2. Opt out of the progressive web app features.

In order to opt out of the progressive web app features, you need to modify your src/index.js file as follows:

  1. Delete the import of the registerServiceWorker.
  2. Delete the registerServiceWorker() call.

Your src/index.js will then look like this:

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
// Deleted -- import registerServiceWorker from './registerServiceWorker';

ReactDOM.render(<App />, document.getElementById('root'));
// Deleted -- registerServiceWorker();

Once you've made those modifications to your index.js, you can safely delete the registerServiceWorker.js file (which it appears you've already done based on the error message you've posted).

The documentation gives a more plete description of how to opt out and some of the consequences of having a progressive web app.

If you are new to react and need to build apps fast you can try create-react-app by facebook

it a mand line tool that will help you build better react app fast with zero configuration you can learn more from the link above and its easy to use

also make sure that you use a good editor that can help you catch errors and to help you and give you good answer the second time please provide your code to understand the problem well .

发布评论

评论列表(0)

  1. 暂无评论