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

Astro Cloudflare - Failed to publish your Function. Got error: Error 8000057: Overlapping rules in _routes.json are not allowed. #135

Closed
1 task
smastrom opened this issue Jan 19, 2024 · 8 comments · Fixed by #137
Assignees
Labels
- P4: important Violate documented behavior or significantly improves performance (priority) pkg: cloudflare

Comments

@smastrom
Copy link

smastrom commented Jan 19, 2024

Astro Info

Astro                    v4.2.1
Node                     v21.5.0
System                   macOS (arm64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/cloudflare
Integrations             @storyblok/astro
                         @astrojs/preact
                         @astrojs/sitemap

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

Hello, I'm developing an Astro website with static pages generated at the following paths:

  • /companies/index.astro
  • /companies/[slug].astro
  • /blog/index.astro
  • /blog/[slug].astro

Any other page is server-side rendered.

In order to avoid the _routes.json 100-entries limit error addressed in withastro/astro#6516, I'm manually excluding the static paths as described in the docs:

adapter: cloudflare({
   routes: {
      exclude: ['/companies/*', '/blog/*'],
   },
})

The redundant paths /companies/ and /blog/ are not stripped away from the generated _routes.json if I have set the following redirect in 404.astro:

---
return Astro.redirect('/', 301)
---

Causing the following deploy error (as /companies/* and /blog/* are also present in the _routes.json file):

Error: Failed to publish your Function. Got error: Error 8000057: Overlapping rules in `_routes.json` are not allowed. Rule "/companies/" is overlapped by "/companies/*". Remove one of the rules to continue.

Generated routes.json

{
  "version": 1,
  "include": [
    "/*"
  ],
  "exclude": [
    "/companies/",
    "/companies/*",
    "/blog/",
    "/blog/*",
    // ...
  ]
}

What's the expected result?

{
  "version": 1,
  "include": [
    "/*"
  ],
  "exclude": [
    "/companies/*",
    "/blog/*",
    // ...
  ]
}

Link to Minimal Reproducible Example

https://stackblitz.com/edit/withastro-astro-cykvsk?file=dist%2F_routes.json

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jan 19, 2024
@alexanderniebuhr alexanderniebuhr transferred this issue from withastro/astro Jan 19, 2024
@alexanderniebuhr alexanderniebuhr added pkg: cloudflare - P4: important Violate documented behavior or significantly improves performance (priority) and removed needs triage Issue needs to be triaged labels Jan 19, 2024
@alexanderniebuhr alexanderniebuhr self-assigned this Jan 19, 2024
@mattpaz
Copy link

mattpaz commented Jan 28, 2024

I recently started to test this. I'm encountering the 8000057 issue with the 9.0.0 release.

Overlapping rules in _routes.json are not allowed

Here's my Astro Info:

Astro                    v4.2.6
Node                     v20.11.0
System                   macOS (arm64)
Package Manager          npm
Output                   hybrid
Adapter                  @astrojs/cloudflare
Integrations             @astrojs/tailwind
                         @astrojs/svelte

Thus far, I'm unable to isolate where the point of failure is so far.

I have several /api endpoints, nested sub directories alongside several Astro.redirect touch points. It is mostly SSR alongside a few static touch points.

That probably isn't enough to jog any ideas, but on the chance it provides a eureka moment about some edge cases, I thought I'd provide some preliminary feedback.

If you have any tips/thoughts, let me know.

Thanks!

@alexanderniebuhr
Copy link
Member

The overlapping issue should be fixed. You could provide a reproduction example, and I can check.

@MehrdadKhnzd
Copy link

Hi! I just started to face the same issue. It was working until recently without any problems.
Now, pages x/* and x/*/y (and any other route with the same structure) will throw the exact same error:
Error: Failed to publish your Function. Got error: Error 8000057: Overlapping rules in "_routes.json" are not allowed. Rule "/x/*/y" is overlapped by "/x/*". Remove one of the rules to continue.
This is totally breaking my software and prevents me from deploying any updates. I came to open a new issue but found this. Please let me know what you think.

@alexanderniebuhr
Copy link
Member

This is totally breaking my software and prevents me from deploying any updates. I came to open a new issue but found this. Please let me know what you think.

I'm sorry to hear that.
Please open a new issue with a reproducible example for your specific issue using https://astro.new

@EskelCz
Copy link

EskelCz commented Feb 9, 2024

This is totally breaking my software and prevents me from deploying any updates. I came to open a new issue but found this. Please let me know what you think.

I'm sorry to hear that. Please open a new issue with a reproducible example for your specific issue using https://astro.new

@alexanderniebuhr I have the same issue. Astro supports these "overlaps", but it seems these generated _routes don't. Is that something that cloudflare can/will improve, or is that a fundamental limitation and we have to work around it?

My build error:

Error 8000057: Overlapping rules in `_routes.json` are not allowed. Rule "/game/*/form" is overlapped by "/game/*". Remove one of the rules to continue.

@alexanderniebuhr
Copy link
Member

Generally it is not an issue. Please also create an example for your specific case.
I also want to let you know that the new version of the Cloudflare adapter, currently in development, will have a new _routes.json generation

@whoiscarlo
Copy link

This is totally breaking my software and prevents me from deploying any updates. I came to open a new issue but found this. Please let me know what you think.

I'm sorry to hear that. Please open a new issue with a reproducible example for your specific issue using https://astro.new

@alexanderniebuhr I have the same issue. Astro supports these "overlaps", but it seems these generated _routes don't. Is that something that cloudflare can/will improve, or is that a fundamental limitation and we have to work around it?

My build error:

Error 8000057: Overlapping rules in `_routes.json` are not allowed. Rule "/game/*/form" is overlapped by "/game/*". Remove one of the rules to continue.

Any updates on this? @EskelCz were you able to find a work around?

@alexanderniebuhr
Copy link
Member

The workaround is to provide your own custom _routes.json file in public/_routes.json.
v10 of the adapter which should release this week, should also fix the issue hopefully

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P4: important Violate documented behavior or significantly improves performance (priority) pkg: cloudflare
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants