title: Angular 7 Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script
body: <p>I am getting the following error</p>
  
  <pre><code>ERROR Error: Uncaught (in promise): TypeError: Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script.
  TypeError: Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script.
  </code></pre>
  
  <p>I used the prompt "ng add @angular/pwa" to add my ngsw-config.json and manifest file.  This prompt also added my "serviceWorker" : true statement and my register with environment to my app.module.ts</p>
  
  <p>After verifying everything was added properly I then ran the command "ng build --prod" that built successfully and the dist shown was made
  <a href="https://i.stack.imgur.com/CfOxm.png" rel="noreferrer">dist folder</a></p>
  
  <p>Then I ran "ng serve --prod" and I am receiving the errors shown in the image
  <a href="https://i.stack.imgur.com/i10yl.png" rel="noreferrer">errors</a></p>
  
  <p>Line being used in app.module.ts</p>
  
  <pre><code>ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production })
  </code></pre>
  
  <p>ngsw-configuration:</p>
  
  <pre><code>{
    "index": "/",
    "assetGroups": [
      {
        "name": "app",
        "installMode": "prefetch",
        "resources": {
          "files": [
            "/favicon.ico",
            "/index.html",
            "/*.css",
            "/*.js"
          ]
        }
      }, {
        "name": "icons",
        "installMode": "lazy",
        "updateMode": "prefetch",
        "resources": {
          "files": [
            "/icons/**"
          ]
        }
      }
    ]
  }
  </code></pre>
  
  <p>Placement of serviceWorker true in angular.json:</p>
  
  <pre><code>"configurations": {
              "production": {
                "serviceWorker": true,
                "fileReplacements": [
                  {
                    "replace": "src/environments/environment.ts",
                    "with": "src/environments/environment.prod.ts"
                  }
                ],
  </code></pre>