https://jsfiddle.net/zcrtmdsx/1/
When using
pwa: {
workbox: {
importScripts: ["my-script.js"],
dev: true,
config: undefined
}
}
The compilation crashes because config is undefined:
if (options.config.debug === undefined) {
// Debug field is by default set to true for localhost domain which is not always ideal
options.config.debug = options.dev || this.options.dev
}
And it's the only way to not have it added:
<% if (options.config) {%>
// Set workbox config
workbox.setConfig(<%= JSON.stringify(options.config, null, 2) %>)
<% } %>
To be able to not have the setConfig in sw.js so we can use workbox in importScripts
There is a compilation error:
FATAL Cannot read property 'debug' of undefined 12:50:35
at ModuleContainer.getOptions (node_modules\@nuxtjs\pwa\lib\workbox\options.js:88:22)
at nuxt.hook (node_modules\@nuxtjs\pwa\lib\workbox\module.js:9:32)
at fn (node_modules\hable\lib\hookable.js:50:45)
at promise.then.previous (node_modules\hable\lib\utils.js:15:67)
at process._tickCallback (internal/process/next_tick.js:68:7)
If I set a value for config, the setConfig is added and I get the following error because I am using workbox in 'my-script.js':
Config must be set before accessing workbox.* modules
I have this error right now. Has this been fixed yet?
I have this error right now. Has this been fixed yet?
I was having the same problem when trying to "background sync". I resolved it as follows:
nuxt.config.js
pwa: {
workbox: {
dev: true,
offlineStrategy: 'StaleWhileRevalidate',
runtimeCaching: [
{
urlPattern: 'https://cdn.com/.*',
}
],
workboxExtensions: [ /* importScripts causes failure */
'static/bg-sw.js'
]
}
}
@valdeir2000 answer seems best approach. In other scripts, you may need to import workbox again.
Most helpful comment
I was having the same problem when trying to "background sync". I resolved it as follows:
nuxt.config.js