rishabh3112 / gridsome-plugin-pwa

PWA plugin for gridsome
MIT License
30 stars 18 forks source link

Export issue #22

Open idealley opened 4 years ago

idealley commented 4 years ago

I have the following error message in the console:

.../node_modules/register-service-worker/index.js:18
export function register (swUrl, hooks) {
^^^^^^

The export is not understood by const { register } = require('register-service-worker') in gridsome.client.js

Just moving the code as follow solved the issue for me:

from

const { register } = require('register-service-worker');
const clientConfig = function (Vue, options, context) {
  let {head, isClient} = context;
  if (process.env.NODE_ENV === 'production' && isClient) {

to

const clientConfig = function (Vue, options, context) {
  let {head, isClient} = context;
  if (process.env.NODE_ENV === 'production' && isClient) {
    const { register } = require('register-service-worker');
rishabh3112 commented 4 years ago

Thanks for opening issue! Please share a minimum reproducible repository.

cartoonmadrasah commented 4 years ago

Having same issue here.

Berkmann18 commented 4 years ago

Same issue here.

Here's my gridsome.config.js:

const manifest = require('./static/manifest.json');

module.exports = {
  siteName: 'SiteNameHere',
  plugins: [
    {
      use: 'gridsome-plugin-manifest',
      options: manifest
    },
    {
      use: 'gridsome-plugin-pwa',
      options: {
        title: manifest.name,
        startUrl: manifest.scope,
        display: manifest.display,
        statusBarStyle: 'default',
        manifestPath: './static/manifest.json',
        cachedFileTypes: 'js,json,css,html,png,jpg,jpeg,svg',
        shortName: manifest.shortName,
        themeColor: manifest.theme_color,
        backgroundColor: manifest.background_color,
        icon: manifest.icon_path,
        msTileImage: manifest.icon_path,
        msTileColor: manifest.theme_color
      }
    }

Changing the package by removing export to module. exports = {register, unregister}; resolves the issue, although it's a hack that won't persist on fresh builds.

coding-sunshine commented 4 years ago

Same error