gridsome-plugin-pwa icon indicating copy to clipboard operation
gridsome-plugin-pwa copied to clipboard

Export issue

Open idealley opened this issue 4 years ago • 4 comments

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');

idealley avatar Jan 24 '20 23:01 idealley

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

rishabh3112 avatar Jan 25 '20 06:01 rishabh3112

Having same issue here.

cartoonmadrasah avatar Feb 06 '20 15:02 cartoonmadrasah

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.

Berkmann18 avatar Feb 11 '20 21:02 Berkmann18

Same error

coding-sunshine avatar Mar 09 '20 14:03 coding-sunshine