oliviertassinari / serviceworker-webpack-plugin

Simplifies creation of a service worker to serve your webpack bundles. :recycle:
https://oliviertassinari.github.io/serviceworker-webpack-plugin/
MIT License
458 stars 76 forks source link

import runtime from 'serviceworker-webpack-plugin/lib/runtime'; always throws error #83

Closed sandshrma closed 6 years ago

sandshrma commented 6 years ago

import runtime from 'serviceworker-webpack-plugin/lib/runtime'; always throws below error

Error: serviceworker-webpack-plugin: It seems that your are importing "serviceworker-webpack-plugin/lib/runtime" without using the plugin.

I installed 'serviceworker-webpack-plugin' by npm install serviceworker-webpack-plugin@0 for 'webpack 1'

Versions.

browser: chrome
browser version: Version 67.0.3396.99 
operating system: IOS
webpack version: 1.14.0

Repro steps.

1). var ServiceWorkerWebpackPlugin = require('serviceworker-webpack-plugin'); // require plugin into the webpack config file 2). added following to webpack plugins

 new ServiceWorkerWebpackPlugin({
        entry: path.join(__dirname, '../src/ServiceWorker/service-worker.js'),
        fileName: 'service-worker.js',
        excludes: ['**/.*', '**/*.map', '*.html']
      })

3). import runtime from 'serviceworker-webpack-plugin/lib/runtime'; in the main.js file always throws error.

runtime.js file always throws error as we can see into the source code.

when I change import runtime from 'serviceworker-webpack-plugin/lib/runtime'; to import runtime from 'serviceworker-webpack-plugin/lib/runtimeTemplate'; it builds, but then I'm getting another error on the browser.

_client.js?cf27:63 ReferenceError: serviceWorkerOption is not defined
    at Object.register (eval at <anonymous> (main.js?48625b094889c52616ad:3544), <anonymous>:13:30)_

we are not getting serviceWorkerOption into global. I'm not sure how serviceWorkerOption is being injected into the global.

sandshrma commented 6 years ago

This was the server-side rendering issue. import runtime from 'serviceworker-webpack-plugin/lib/runtime'; was calling on the server side.