question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Service Worker required when disabled in dev

See original GitHub issue

What is the current behaviour? When running preact watch --sw false it still tries to attach a service worker. preact watch works fine which should default sw to false (https://github.com/preactjs/preact-cli#preact-watch).

Steps to Reproduce

  1. Use a project without a .\src\sw.js
  2. Run preact watch --sw false
  3. See error

Build failed!

× ERROR Entry module not found: Error: Can’t resolve ‘.\src\sw.js’ in ‘.\src’ × ERROR InjectManifest: Entry module not found: Error: Can’t resolve ‘.\src\sw.js’ in ‘.\src’

What is the expected behaviour? Build should succeed using same behavior as preact watch which defaults sw to false

Please mention any other relevant information I’m assuming it was introduced in https://github.com/preactjs/preact-cli/commit/9f9277be2ed50476147bae5567640b36740b4d38

Environment Info:

System: OS: Windows 10 10.0.19043 Binaries: Node: 14.16.1 - C:\Program Files\nodejs\node.EXE
npm: 6.14.12 - C:\Program Files\nodejs\npm.CMD Browsers: Edge: Spartan (44.19041.1023.0), Chromium (93.0.961.47) npmPackages: preact: ^10.5.14 => 10.5.14 preact-cli: ^3.2.2 => 3.2.2 preact-render-to-string: ^5.1.19 => 5.1.19 preact-router: ^3.2.1 => 3.2.1

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rschristiancommented, Sep 15, 2021

https://github.com/preactjs/preact-cli/blob/b3b6984a1d022ac3348784061bd8864f66f2d670/packages/cli/lib/lib/webpack/webpack-client-config.js#L41

Looks like we’re not converting the “false” into a boolean in watch mode as we do in build, just passing the string value through.

Will try to get a fix together here.

0reactions
rschristiancommented, Sep 16, 2021

Sorry, I don’t understand. You can customize the config as-is:

export default {
    /**
     * Function that mutates the original webpack config.
     * Supports asynchronous changes when a promise is returned (or it's an async function).
     *
     * @param {object} config - original webpack config.
     * @param {object} env - options passed to the CLI.
     * @param {WebpackConfigHelpers} helpers - object with useful helpers for working with the webpack config.
     **/
    webpack(config, env, helpers) {
        if (env.isWatch) {
            const manifestPlugin = helpers.getPluginsByName(config, 'InjectManifest')[0];
            // You can make any modifications you'd like to the manifestPlugin here
        }    
    }
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Disable service workers when in development mode.
This solution is specific to a NextJS project using Next-PWA library to implement PWA, but it uses Google's Workbox under the hood to...
Read more >
Using Service Workers - Web APIs | MDN
In Firefox, Service Worker APIs are hidden and cannot be used when the user is in private browsing mode, or when history is...
Read more >
How to unregister service workers ? | by himank bhalla | Medium
It will list all the registered service workers. Click on unregister to disable that particular service worker. Web Development.
Read more >
How to Unregister Service Workers? - Coding Blocks Blog
Click on tools => web developer => service workers. It will list all the registered service workers. Click on unregister to disable that ......
Read more >
Disable service workers by default - zuul - OpenDev
The Service Workers seem to be consistently causing issues for people that are strange, meaning many of our deployers are disabling them.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found