Git Product home page Git Product logo

Comments (3)

oliviertassinari avatar oliviertassinari commented on June 15, 2024

It should be working. Might be linked to a wrong configuration of the plugin. Does that work in production?

from serviceworker-webpack-plugin.

thehig avatar thehig commented on June 15, 2024

I'm having the same issue, [Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script.]. I'm currently investigating my webpack config

Edit: It's almost certainly a webpack issue in that /sw.js is not resolving to the service worker file. Somehow webpack needs to be told to serve that js file/route.

Edit: I can make some parts work by manually serving the sw.js file. The two separate ways I achieved this were:

Adding the following to webpack.config devServer object:

    setup: app => {
      app.use('/', express.static(path.join(__dirname, 'src')));
    }

however, this shares far more than intended.

Secondly I tried using the webpack public folder. I moved the sw.js file into the public folder. This made the file serve properly without oversharing. However, this does not transpile the sw.js file.
After manual transpilation it throws errors that global is not defined, which makes me think it's not linked in properly with the plugin.

What is the 'right' way to serve this js file, but without affecting/sharing the rest of my JS files?

Edit:
I think I fixed this. It turned out that all I had to do was add a publicPath property since my webpack config outputs to '/assets/'

    new ServiceWorkerWebpackPlugin({
      entry: path.join(__dirname, 'src/service-worker.js'),
      publicPath: '/assets/'
    }),

from serviceworker-webpack-plugin.

oliviertassinari avatar oliviertassinari commented on June 15, 2024

@thehig Thanks for letting us know! I'm going to improve the docs a bit.

from serviceworker-webpack-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.