简体   繁体   English

运行 npm 运行构建后反应应用程序更改未更新

[英]React app changes not updaiting after running npm run build

I have a react app with the following file structure:我有一个具有以下文件结构的反应应用程序:

在此处输入图像描述

When I run npm run build the app compiles everything using webpack and npm gives me the following output:当我运行npm run build应用程序编译所有使用webpack和 npm 给我以下 Z78E6221F6393D4356868:

在此处输入图像描述

In the output (build folder), it creates an asset-manifest.json file, containing the newly created files:在 output(构建文件夹)中,它创建了一个asset-manifest.json文件,其中包含新创建的文件:

{
  "files": {
    "main.css": "/static/css/main.607e5368.chunk.css",
    "main.js": "/static/js/main.08012c8a.chunk.js",
    "main.js.map": "/static/js/main.08012c8a.chunk.js.map",
    "runtime~main.js": "/static/js/runtime~main.a8a9905a.js",
    "runtime~main.js.map": "/static/js/runtime~main.a8a9905a.js.map",
    "static/css/2.8643d4fb.chunk.css": "/static/css/2.8643d4fb.chunk.css",
    "static/js/2.1aae919f.chunk.js": "/static/js/2.1aae919f.chunk.js",
    "static/js/2.1aae919f.chunk.js.map": "/static/js/2.1aae919f.chunk.js.map",
    "index.html": "/index.html",
    "precache-manifest.ca81004b99ff7fc6f769d98332234f01.js": "/precache-manifest.ca81004b99ff7fc6f769d98332234f01.js",
    "service-worker.js": "/service-worker.js",
    "static/css/2.8643d4fb.chunk.css.map": "/static/css/2.8643d4fb.chunk.css.map",
    "static/css/main.607e5368.chunk.css.map": "/static/css/main.607e5368.chunk.css.map",
    "static/media/index.scss": "/static/media/slick.f97e3bbf.svg"
  }
}

However, if I go into my browser the react app doesn't update and keeps using the old filenames.但是,如果我 go 进入我的浏览器,反应应用程序不会更新并继续使用旧文件名。 If I go to the network inspector I can see that the files are loaded with 200 OK (from ServiceWorker) .如果我 go 到网络检查员,我可以看到文件已加载200 OK (from ServiceWorker)

Why are the newly genrated files not being used in the new index.html?为什么新生成的文件没有在新索引中使用。html?

I've tried clearing my cache, using a clean installation of the template, using another browser, using incognito mode,...我尝试清除缓存,使用模板的全新安装,使用另一个浏览器,使用隐身模式,...

It is due to service worker.这是由于服务人员。 Unregister your service worker to show updated content取消注册您的服务人员以显示更新的内容

In your index.js or whatever is main file in react app在您的 index.js 或任何反应应用程序中的主文件中

// import registerServiceWorker from './registerServiceWorker'; // comment this line
import { unregister } from './registerServiceWorker';

Comment registerServiceWorker()评论registerServiceWorker()

// registerServiceWorker() 
unregister();// add this

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 更新 React + Django 上的更改,而无需每次都运行“npm run build” - Update changes on React + Django without running "npm run build" everytime 在我的反应应用程序上运行“npm run deploy”后提交对 git 的更改时出现问题 - Problems when it comes to committing changes to git after running 'npm run deploy' on my react app 在部署到 heroku 并运行 npm 构建后对应用程序进行更改 - Making changes to app after deploy to heroku and running npm build 为基于 create-react-app 的项目运行 npm build 后,在运行时读取环境变量 - Reading environment variable in run time after running npm build for a create-react-app based project 运行“npm run build”后如何在 React 应用程序上编辑和显示更新 - How to edit and show updates on React app after running 'npm run build' 运行“npm run build”后“sh: 1: react-scripts: not found” - "sh: 1: react-scripts: not found" after running "npm run build" 反应:404/运行`npm run build`后没有文件夹结构 - React: 404/No folder structure after running `npm run build` 使用 npm 运行构建反应应用程序后出现白屏 - white screen after using npm run build react app API URL 更改后 npm 构建反应 - API URL changes after npm build React 为什么我收到错误:运行 npm ci & run npm 构建失败时,将更改推送到部署在 Firebase 上的 React 应用程序? - Why do I get error: run npm ci & run npm build failed when pushing changes to React app that is deployed on Firebase?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM