title: How to import a script in Service Worker when using Webpack
body: <p>In a Service Worker, I'm trying to import another helper script using importScripts, however I keep getting a <code>Uncaught DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'http://localhost:5000/src/js/utility.js' failed to load.</code></p>
  
  <p>I have the following code in the Service Worker:</p>
  
  <pre class="lang-js prettyprint-override"><code>importScripts('../src/js/utility.js');
  
  workbox.routing.registerRoute(/.*(?:jsonplaceholder\.typicode)\.com.*$/, function(args){
      console.log('Json placeholder being called');
      // Send request to the server.
      return fetch(args.event.request)
          .then(function(res){
              // Clone the response obtained from the server.
              var clonedRes = res.clone();
              // Clear data stored in the posts store.
              clearAllData('posts') // Function from helper file
                  .then(function(){
                      return clonedRes.json()
                  })
                  .then(function(data){
                      for(var key in data){
                          // Write the updated data to the posts store.
                          writeData('posts', data[key]) // Function from helper file
                      }
                  });
  
              return res;
          })
  });
  
  workbox.precaching.precacheAndRoute(self.__precacheManifest);
  </code></pre>
  
  <p>And in <code>utility.js</code> I have the following code:</p>
  
  <pre class="lang-js prettyprint-override"><code>import { openDB } from 'idb';
  
  export function writeData(st, data){
      console.log(st, data);
  }
  
  export function clearAllData(st){
      console.log(st);
  }
  </code></pre>
  
  <p>The functions don't do anything yet, but even these placeholder ones don't work! Eventually I'd like to be able to use the <code>idb</code> npm module, so that's why I'm doing this in a helper, so I can also use it from my normal Javascript file.
  <br>
  Also I'm using Webpack to build my files, and in another project where I don't use it, it works fine, however in this one it just doesn't find the file after building, so I'm thinking Webpack may be screwing something up.</p>
  
  <p>Thanks in advance :)</p>