Problem: Vue 3 build does not generate service worker

After adding the

"@vue/cli-plugin-pwa": "^4.5.12"
to my package.json and setting up workbox configuration in my vue.config.js, I encountered an issue. When running npm run build:prd with the script
vue-cli-service build --mode prod.example
, I noticed that the service-worker.js file was missing from my dist folder.

This is what my vue.config.js looks like:

module.exports = {
    // ...other vue-cli plugin options...
    pwa: {
        // configure the workbox plugin
        workboxPluginMode: 'InjectManifest',
        workboxOptions: {
            // swSrc is required in InjectManifest mode.
            swSrc: 'src/service-worker.js',
            // ...other Workbox options...
        }
    }
}

I attempted moving the PWA plugin configuration into my package.json, but this did not resolve the issue either. The service-worker.js file still couldn't be found in the dist folder.

To temporarily address this problem, I resorted to placing the service-worker.js in my public folder. However, this caused another problem as the service worker wouldn't update automatically with each new release. My goal is to notify the client when a new version is available, but because the service-worker.js remains static, I am unable to trigger the update event.

Answer №1

After investigating, I discovered that @vue/cli-plugin-pwa will only create a service-worker file if the

process.env.NODE_ENV === 'production'
. In my project, however, when I execute npm run build, the NODE_ENV remains at development instead of automatically switching to production. I am unsure of the cause of this behavior, but I managed to fix it by manually adding NODE_ENV=production to all of my .env files. This adjustment ensures that precache-manifest....js is generated during each build process.

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

What is the best way to extract a JSON value and use it across multiple functions?

Currently, everything seems to be working fine. However, I'm unsure about the correct way to call the json data. I attempted using a direct link but it didn't work. Do I need to modify the "data" parameters? I'm confused because I saw that ...

Ensure that the input box expands to occupy the entire HTML page

After reviewing numerous pages and questions related to this topic, I have located the correct solution but am struggling to implement it. My goal is to achieve a similar outcome to the second question, but I'm having difficulty figuring out how to do ...

My JavaScript/Jquery functions are not running as expected

I need some help creating a simple image rotation feature. I have a folder named comics where the images are stored locally with names like comic_(number). However, when I click my buttons, nothing happens. The previous button doesn't even get disable ...

How can I use JavaScript to show a div upon clicking an input element?

I am looking to make a block div visible when an input field is clicked. <input class="indifferent" type="radio" name="decision" value="indifferent"> Indifferent </br> <div class="input" style="display: none;"> Please assist with our com ...

Potential delay in mounting Rails Webpacker + Vue components when webpack-dev-server is not utilized

Production Delay in Rendering Process While using webpack-dev-server, all components are rendered quickly and function flawlessly. However, when running the application solely through rails s in both development and production, I can witness a noticeable ...

Get the XML element containing the desired value in the downloadURL

Seeking assistance from experienced individuals regarding XML usage. Admitting to my lack of knowledge in this area, I am a beginner and seeking patience. I have successfully implemented code that loads marker data from a MySQL database and displays it on ...

How can JavaScript be used to access response header information in Devise Token Auth?

Currently, I am in the process of developing a web application using Rails as the backend API and Vue.js as the frontend library. For authentication purposes, I have integrated the devise_token_auth library. However, I am facing difficulty in retrieving th ...

The focus functionality in Angular seems to be malfunctioning

Having trouble with simple focus in Angular <div class="search pull-right tab-{{ showDetails2 }}" data-ng-click="showDetails2 = !showDetails2; showDetails = false; showDetails1 = false;searchFocus();"> html <input type="text" data-ng-model="mod ...

Using JavaScript to auto-scroll a textarea to a certain position

Is there a way to change the cursor position in a textarea using JavaScript and automatically scroll the textarea so that the cursor is visible? I am currently using elem.selectionStart and elem.selectionEnd to move the cursor, but when it goes out of view ...

Unpacking and reassigning variables in Vue.js 3 using TypeScript

I am working with a component that has input parameters, and I am experimenting with using destructuring assignment on the properties object to reassign variables with different names: <script setup lang="ts"> const { modelValue: isSelected ...

``Why do my values keep vanishing after refresh?

After logging in, I set the username and loggedIn values. However, when refreshing the page, these values reset to their original states. Why is this happening? I never encountered this issue when using Vuex in Vue 2. Do I really need to store this data i ...

The proper method for developing Vue components that are dependent on the parent build tools

In my experience, this issue might also arise in other frameworks with plugin/component ecosystems that rely on specific build tools (such as React components with JSX). While Vue serves as my use-case. Having developed numerous Vue components as single . ...

Adding to an existing array in MongoJS

I have been attempting to append data to an existing array in my mongoDB. The code snippet below is what I currently have, but unfortunately, it does not work as expected since all the existing data gets wiped out when I try to add new data: db.ca ...

Struggling to integrate Parse-server with vue.js

Struggling with setting up a project that incorporates parse-server in a Vuetify 3 project. Here are the steps to follow: To get started, install Parse by running npm install parse @types/parse. Create a file called parse.ts for configuration and initiali ...

What is the best way to eliminate "?" from the URL while transferring data through the link component in next.js?

One method I am utilizing to pass data through link components looks like this: <div> {data.map((myData) => ( <h2> <Link href={{ pathname: `/${myData.title}`, query: { ...

Keep going in the for await loop in NodeJS

My code snippet looks like this: for await (const ele of offCycles) { if ((await MlQueueModel.find({ uuid: ele.uuid })).length !== 0) { continue; } <do something> } I'm curious if it's possible to use a continue st ...

Determining Equality in JavaScript: Comparing 2 Objects

I'm currently working with 2 objects that will always have the same amount of properties, but their values may vary. In my attempt to check if the two objects hold the same values, I decided to use the .every method. However, all results are returnin ...

What is the best way to mention @here with an attachment?

I'm attempting to use the canvas say command to display an image with an @here mention included, but unfortunately it only shows the image without making the mention. Below is what I have attempted: message.channel.send(`@here\n`+attachment); ...

Error encountered when attempting to insert data into a PostgreSQL database using Node.js and Sequelize

I'm currently using the node sequelize library to handle data insertion in a postgress database. Below is the user model defined in the Users.ts file: export class User extends Sequelize.Model { public id!: number; public name: string; public ...

Convenient ways to connect data between a database and Firebase authentication system

After beginning a basic app using Firebase 3 and Angular 1, I implemented an authentication system through Firebase for user registration and login. Currently, I am storing message data in the Firebase database. My main question is: how can I connect user ...