Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: workbox.strategies[options.offlineStrategy] is not a constructor #365

Closed
harish0507 opened this issue Oct 7, 2020 · 3 comments

Comments

@harish0507
Copy link

offlineStrategy options is not available in generated sw.js file

Screenshot 2020-10-07 at 1 56 45 PM

Nuxt version: 2.14.6
Nuxt PWA version: 3.1.0

// nuxt.config.js
pwa: {
	workbox: {
		dev: true,
		config: process.env.NODE_ENV !== 'development' ? false : {
			debug: process.env.NODE_ENV === 'development'
		},
		cleanupOutdatedCaches: true,
		offline: false,
		runtimeCaching: [
			{
				urlPattern: 'https://(s3-|s3.)?(.*).amazonaws.com/.*',
				handler: 'cacheFirst',
				strategyOptions: {
					cacheName: 's3',
					cacheExpiration: {
						maxEntries: 100,
						maxAgeSeconds: 3600
					}
				}
			},
			{
				urlPattern: '/images/.*',
				handler: 'cacheFirst',
				strategyOptions: {
					cacheName: 'images',
					cacheExpiration: {
						maxEntries: 20,
						maxAgeSeconds: 3600
					}
				}
			},
			{
				urlPattern: '/api/.*',
				handler: 'networkOnly'
			}
		]
	}
}

Proposed Solution

Seems like offlineStrategy options is missing in @nuxtjs/pwa/lib/workbox/module.js

// Add sw.js
if (options.swTemplate) {
    await this.addTemplate({
        src: options.swTemplate,
        fileName: options.swDest,
        options: {
            swOptions: pick(options, [
                'workboxURL',
                'importScripts',
                'config',
                'cacheNames',
                'clientsClaim',
                'skipWaiting',
                'cleanupOutdatedCaches',
                'offlineAnalytics',
                'preCaching',
                'runtimeCaching',
                'offlinePage',
                'offlineStrategy' // Added missing option
            ]),
            routingExtensions: await readJSFiles.call(this, options.routingExtensions),
            cachingExtensions: await readJSFiles.call(this, options.cachingExtensions),
            workboxExtensions: await readJSFiles.call(this, options.workboxExtensions)
        }
    })
}
@simllll
Copy link
Contributor

simllll commented Oct 7, 2020

The code block looked like this before:
// Add sw.js

  if (options.swTemplate) {
     await this.addTemplate({
       src: options.swTemplate,
       fileName: options.swDest,
       options: {
         ...options,
         routingExtensions: await readJSFiles.call(this, options.routingExtensions),
         cachingExtensions: await readJSFiles.call(this, options.cachingExtensions),
         workboxExtensions: await readJSFiles.call(this, options.workboxExtensions)
       }
     })
   }

therefore it seems legit that it worked before, but doesn't now when pick is used.

Breaks in 3.1.0

@victorgarciaesgi
Copy link

I have this error too!

@pi0 pi0 closed this as completed in 2b9856e Oct 7, 2020
@pi0
Copy link
Member

pi0 commented Oct 7, 2020

Should be fixed by v3.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants