无法编译反应应用程序,因为它显示“未找到模块” [英] Unable to compile react application as it says "Module not found"
问题描述
我一直在尝试执行一个非常简单的反应应用程序,但由于某种原因我无法编译它。当我尝试使用npm start在bash中编译它时,我收到错误,指出编译失败:./ src / index.js
模块未找到:无法解析'./registerServiceWorker'in' / Users / Pruthvi / Desktop / ReactApplication / my-app / src'
I have been trying to execute a very simple react application, but for some reason I'm unable to compile it. When i try to compile it in bash using "npm start", i get the error stating "Failed to compile: ./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!
推荐答案
默认情况下, create-react-app
将创建一个渐进的Web应用程序,如文档 here 。渐进式Web应用程序依赖 registerServiceWorker.js
文件中的 registerServiceWorker()
。您显然删除了此文件,因此您的项目不再构建。
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.
您有两种选择:
- 将您的项目保持为渐进式网络应用程序,在这种情况下,您应该只是恢复首次创建后的原始状态。
- 选择退出渐进式网络应用程序功能。
要退出渐进式网页应用功能,您需要修改 src / index .js
文件如下:
In order to opt out of the progressive web app features, you need to modify your src/index.js
file as follows:
- 删除
import
registerServiceWorker
。 - 删除
registerServiceWorker()
调用。
- Delete the
import
of theregisterServiceWorker
. - Delete the
registerServiceWorker()
call.
您的 src / index.js
将如下所示:
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();
一旦你对 index.js进行了修改
,您可以安全地删除 registerServiceWorker.js
文件(根据您发布的错误消息,您已经完成了该文件)。
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).
该文档提供了对如何选择退出和一些拥有渐进式Web应用程序的后果。
The documentation gives a more complete description of how to opt out and some of the consequences of having a progressive web app.
这篇关于无法编译反应应用程序,因为它显示“未找到模块”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!