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

Async Function (RouteMatchCallback, RouteHandler, etc.) is not being included in the generated sw.js #822

Open
Kuro091 opened this issue Feb 6, 2025 · 2 comments

Comments

@Kuro091
Copy link

Kuro091 commented Feb 6, 2025

Example:

const simpleTest = () => {
    return "abc"
}


cacheName: 'keys-and-remotes',
      urlPattern: async () => {
        return await simpleTest('/cars/keys-and-remotes');
      },
      handler: async ({ request }) => handleRouteGroupItemRequest(request, 'keys-and-remotes'),

the generated sw.js

   (no declaration of simpleTest or handleRouteGroupItemRequest any where)

  workbox.registerRoute(/^(http|https):\/\/[a-zA-Z0-9\-\.]+(:[0-9]+)?(\/cars\/gas-cards(\?[^#]*)?)$/gm, async ({
    request
  **}) => handleRouteGroupItemRequest(request, "gas-cards"), 'GET');**
  workbox.registerRoute(async () => {
    return await simpleTest("/cars/keys-and-remotes");
  }, async ({
    request
.....

This leads to functions not being found error. Anything I can do in my ts.config for example to fix this?

@userquin
Copy link
Member

userquin commented Feb 6, 2025

You cannot use external functions, the code is serialized by workbox-build: you can use custom service worker (injectManifest strategy) or inline any function call

@Kuro091
Copy link
Author

Kuro091 commented Feb 6, 2025

Thanks for the quick response

I'm moving from generateSw to injectManifest right now which seems to work

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

2 participants