Vue PWA - manifest.json replaced upon refreshing the page

I'm encountering an issue with my Progressive Web App (PWA) where reloading the page manually or redirecting using window.location results in the manifest.json file being overwritten with the contents of index.html. This leads to an error stating

Manifest: Line: 1, column: 1, Unexpected token.
Interestingly, when using the Vue Router to change routes, everything works fine until a page reload is triggered.

The PWA is developed through Vue's PWA plugin which utilizes Google Workbox. I have kept the configuration files at their default settings and haven't added any code that would cause this strange behavior. Scouring through my project for mentions of manifest.json didn't reveal anything suggesting its content should be overwritten. Any suggestions on how to resolve this?

manifest.json

{
        "name": "appname",
        "short_name": "app",
        "start_url": "index.html",
        "display": "standalone",
        "background_color": "#f5f5f5",
        "theme_color": "#f5f5f5",
        "orientation": "portrait-primary",
        "icons": [ ... ]
    }
    

index.html

<!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="utf-8">
            <meta http-equiv="X-UA-Compatible" content="IE=edge">
            <meta name="viewport" content="width=device-width,initial-scale=1.0">
            <link rel="icon" href="<%= BASE_URL %>favicon.ico">
            <title>app</title>
            <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900">
            <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Material+Icons">
            <link rel="manifest" href="manifest.json">
            <!-- ios support -->
            <link rel="apple-touch-icon" href="./icons/icon-96x96.png">
            <meta name="apple-mobile-web-app-status-bar" content="#333">
            <meta name="theme-color" content="#333">
        </head>
        <body>
            <noscript>To run this application, JavaScript is required to be enabled.</noscript>
            <div id="app"></div>
            <!-- built files will be auto injected -->
        </body>
    </html>
    

service-worker.js

self.addEventListener('install', evt => {
        console.log('Service worker has been installed');
    })
    
    
    self.addEventListener('activate', evt => {
        console.log('Service worker has been activated')
    })
    
    
    self.addEventListener('fetch', evt => {
        console.log('Fetch Event', evt);
    })
    

registerServiceWorker.js

/* eslint-disable no-console */
    import { register } from 'register-service-worker'
    
    if (process.env.NODE_ENV === 'production') {
      register(`${process.env.BASE_URL}service-worker.js`, {
        ready () {
          console.log(
            'App is being served from cache by a service worker.\n'
          )
        },
        registered () {
          console.log('Service worker has been registered.')
        },
        cached () {
          console.log('Content has been cached for offline use.')
        },
        updatefound () {
          console.log('New content is downloading.')
        },
        updated () {
          console.log('New content is available; please refresh.')
        },
        offline () {
          console.log('No internet connection found. App is running in offline mode.')
        },
        error (error) {
          console.error('Error during service worker registration:', error)
        }
      })
    }
    

vue-config.js

module.exports = {
        pwa: {
            workboxPluginMode: 'InjectManifest',
            workboxOptions: {
                swSrc: './public/service-worker.js'
            }
        }
    }
    

Answer №1

We encountered the same issue and found a solution. Have you tried accessing ?

In our situation, we were hosting the PWA on IIS. The primary problem was that .json files were not recognized as a valid MIME Type in the IIS manager, causing this unexpected behavior. To address this, follow these instructions:

We also referred to this post for guidance on correctly hosting the PWA on IIS:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to modify AJAX response HTML and seamlessly proceed with replacement using jQuery?

I am working on an AJAX function that retrieves new HTML content and updates the form data in response.html. However, there is a specific attribute that needs to be modified before the replacement can occur. Despite my best efforts, I have been struggling ...

Setting up Webpack for my typescript React project using Webpack Version 4.39.2

I have been given the task of fixing the Webpack build in a project that I am currently working on. Despite not being an expert in Webpack, I am facing difficulties trying to make it work. The project has an unconventional react frontend with typescript. I ...

Communicate through Node.js, with messages that multiply based on the total number of users currently in the chat room

Currently, I am working on a project that involves creating a chat application using Node.js. However, I have run into an issue where the message gets repeated for each user in the chat. For example, if there are 4 users in the chat, the message will be di ...

Using XSLT with JavaScript

I am currently working with a set of XML files that are linked to XSLT files for rendering as HTML on a web browser. Some of these XML files contain links that would typically trigger an AJAX call to fetch HTML and insert it into a specific DIV element on ...

Displaying events in the all-day section can be achieved by setting the defaultView of fullCalendar.js to 'agendaDay'

Trying to use fullCalendar.js with defaultView set to agendaDay, and pulling events from mysql as JSON. However, I'm encountering an ERROR where it displays the events in the 'all-Day' section. Here are some of the solutions I attempted: e ...

Displaying a list of JSON data in HTML using Angular.js is a breeze

I am attempting to create an HTML list displaying the id fields of game objects from a json file. However, it is not appearing in my user interface. I am unsure why it is not rendering properly. ---core.js--- var gameapp = angular.module('gameapp&ap ...

When using the setTimeout function to update the state, React useContext appears to be ineffective

As a newcomer to React, I have a question about refreshing the score in my card game within a forEach loop using setTimeout. While the state appears to update correctly, the DOM (Component overarching) does not reflect these changes. export function Refill ...

AngularJS directive not registering event after model update

Within my angularjs application, I have implemented an element directive that is equipped with an event listener. This listener is designed to respond to a broadcast event from the controller. app.directive('listItem', function(){ return { ...

PHP variables that are constantly changing

I recently developed a website that showcases random entries from a database to viewers. Here is the current code snippet I am using: $records = "SELECT * FROM xxx"; $records_query = mysql_query($records); $num_records = mysql_num_rows($records_query); $i ...

There is no information available at this time

Currently, I am delving into Angular and am keen on creating a web application that consumes a Restful Web service. The setup of my page is as follows: <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html ng-app="Tri ...

Building and utilizing xterm.js on your local machine - A step-by-step guide

I have been attempting to modify the source code of xterm.js and test my changes before submitting a PR. Unfortunately, I have not been able to generate a functional 'distribution.' (I apologize if my terminology is incorrect -- I am still fairl ...

Create unique error messages using Vue validators

Two fields named text and email are included in my template. Below is the structure of the template: HTML <!DOCTYPE html> <html> <head> <title>Vue - Validations</title> <script src="Libraries/vue/vue.min.js&qu ...

Is object rest/spread properties not supported by Node.js version 6.3.1?

After attempting to run this code in Node.js v6.3.1 CLI, the following output was generated: let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 }; console.log(x); // 1 console.log(y); // 2 console.log(z); // { a: 3, b: 4 } Unexpectedly, the output was diffe ...

Stop RequireJS from Storing Required Scripts in Cache

It seems that RequireJS has an internal caching mechanism for required JavaScript files. Whenever a change is made to one of the required files, renaming the file is necessary in order for the changes to take effect. The typical method of adding a version ...

When first accessing the page, the map may not load properly. However, a simple refresh of the page in VueJS should resolve this issue and allow the

After initially loading the page, the map may not work properly in Vue.js. However, refreshing the page fixes this issue. Can anyone provide assistance with this problem? Here is the relevant code: mounted() { this.geolocate(); }, methods: { ...

[.TextureUnitWarning] ALERT: Unit 1 is lacking a texture binding for rendering test.html:1

I've been attempting to incorporate texture into my project. var bumptexture = THREE.ImageUtils.loadTexture('grid.jpg'); var normaltexture = THREE.ImageUtils.loadTexture("normal.jpg"); var diffusetexture = THREE.ImageUtils.loadTexture ...

The function window.addEventListener('load') functions properly on desktop computers, but does not work on mobile devices

After developing a react website, I noticed that it functions correctly on PC but not on Mobile devices. componentDidMount() { window.addEventListener('scroll', this.onScroll); // This event works fine window.addEventListener('load&a ...

Convert the contents of the uploaded file to a JSON format

I've recently started using angularjs for file uploads and came across this helpful model on github: https://github.com/danialfarid/angular-file-upload The file upload process is working smoothly for me. However, I'm facing a challenge after upl ...

Having issues with my JavaScript code - it just won't function

I am having an issue with my JavaScript code. I don't receive any errors, but when I click the submit button, nothing happens. I have followed a video tutorial and watched it twice, but I can't seem to figure out what is wrong here. Here is the ...

Vue.Js allows developers to easily set a default selected value in a select dropdown menu

Having trouble with getting the default selected value using select in VueJs. I've attempted two different approaches: Using id and v-model fields in the select like this: <select v-model="sort_brand" id="sort-brand" class="form-control"> ...