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: module.page is not a function when using rewrites #12336

Open
1 task
lilnasy opened this issue Oct 29, 2024 · 16 comments · May be fixed by #12339
Open
1 task

TypeError: module.page is not a function when using rewrites #12336

lilnasy opened this issue Oct 29, 2024 · 16 comments · May be fixed by #12339
Labels
- P2: nice to have Not breaking anything but nice to have (priority) feat: routing Related to Astro routing (scope)

Comments

@lilnasy
Copy link
Contributor

lilnasy commented Oct 29, 2024

Astro Info

Astro                    v4.16.7
Node                     v18.20.3
System                   Linux (x64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/node
Integrations             @astrojs/svelte

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

No response

Describe the Bug

When the target of a rewrite resolves to a prerendered page, the request fails, responding with a blank 500 page.
image

What's the expected result?

Middleware successfully rewrites to a prerendered page.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-1oeqxb?file=src%2Fmiddleware.ts

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 Oct 29, 2024
@ematipico
Copy link
Member

The issue isn't caused by the rewrite. Removing next('/login') doesn't change anything, and the build keeps failing. The error is generated by Container.astro

@ematipico ematipico closed this as not planned Won't fix, can't repro, duplicate, stale Oct 29, 2024
@lilnasy
Copy link
Contributor Author

lilnasy commented Oct 29, 2024

Container.astro is unchanged from the SSR starter template. The error is in fact from the rewrite as the stack trace shows.

@ematipico
Copy link
Member

I see something completely different from your stackblitz

fetch failed
  Stack trace:
    at internal/deps/undici/undici/fetch/< (node:internal/deps/undici/undici:93:355374)
  Caused by:
  other side closed
    at _SocketError (node:internal/deps/undici/undici:93:6681)
    at emit (node:events:30:11015)
    at processTicksAndRejections (node:internal/process/task_queues:192:1068)
    at _0x4a416b (https://github1oeqxb-eydn.w-corp-staticblitz.com/blitz.34c588ed.js:40:198326)
    at _0x4c9d8e/< (https://github1oeqxb-eydn.w-corp-staticblitz.com/blitz.34c588ed.js:40:516062)
    at close (https://github1oeqxb-eydn.w-corp-staticblitz.com/blitz.34c588ed.js:40:1018586)

@lilnasy
Copy link
Contributor Author

lilnasy commented Oct 29, 2024

Might have to do with stackblitz.

@ematipico
Copy link
Member

I also downloaded the reproduction (at the very beginning), and removing the rewrite doesn't have any effect. I still see the error.

@lilnasy
Copy link
Contributor Author

lilnasy commented Oct 29, 2024

Does it say which fetch? build-time/runtime?

@ematipico ematipico added the needs repro Issue needs a reproduction label Oct 29, 2024
@ematipico ematipico reopened this Oct 29, 2024
Copy link
Contributor

Hello @lilnasy. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs repro will be closed if they have no activity within 3 days.

@github-actions github-actions bot removed the needs triage Issue needs to be triaged label Oct 29, 2024
@lilnasy
Copy link
Contributor Author

lilnasy commented Oct 29, 2024

The repro is built by making just a few changes to the SSR starter template. Does it not qualify as minimal?

@ematipico
Copy link
Member

I can't reproduce the error 😞 I don't want to close the issue, but we need a reproduction where I can see your same error.

@lilnasy
Copy link
Contributor Author

lilnasy commented Oct 29, 2024

I mean you are free to let other maintainers tackle it if you can't, but needs repro is not the tag to go with, is it?

video.mp4

@ematipico ematipico added needs triage Issue needs to be triaged and removed needs repro Issue needs a reproduction labels Oct 29, 2024
@ematipico
Copy link
Member

ematipico commented Oct 29, 2024

It wasn't clear that I had to use the preview command, sorry about that.

I mean you are free to let other maintainers tackle it if you can't, but needs repro is not the tag to go with, is it?

Please refrain from making these kinds of comments, I am trying my best, and it happens if I make mistakes

@ematipico ematipico added - P3: minor bug An edge case that only affects very specific usage (priority) feat: routing Related to Astro routing (scope) labels Oct 29, 2024
@github-actions github-actions bot removed the needs triage Issue needs to be triaged label Oct 29, 2024
@lilnasy
Copy link
Contributor Author

lilnasy commented Oct 29, 2024

Sorry. It doesn't come across over github comments, but I didn't mean to be rude. Just meant to point out that other maintainers wouldn't try to triage an issue already tagged with needs repro.

@ematipico
Copy link
Member

ematipico commented Oct 29, 2024

It seems that the issue is that login.astro is marked a prerendered = true, so when Astro compiles for SSR, the logic page is empty. This is the file dist/server/pages/login.astro.mjs

// Contents removed by Astro as it's used for prerendering only

Making the page not prerendered works. I believe this behaviour is intended. I suppose it's also a difficult way to reproduce the intended behaviour in development

@ematipico ematipico added - P2: nice to have Not breaking anything but nice to have (priority) and removed - P3: minor bug An edge case that only affects very specific usage (priority) labels Oct 29, 2024
@lilnasy
Copy link
Contributor Author

lilnasy commented Oct 29, 2024

Is that a documented limitation of rewrites?

@ematipico
Copy link
Member

Probably not, however I don't think it shouldn't be possible to use next("/prerendered"), because this API doesn't re-run the rendering phase, so you can't retrieve the static page.

Did you try to use ctx.rewrite instead?

I'll have to see if it will be able to emit an error/warning for these cases in dev mode.

@lilnasy
Copy link
Contributor Author

lilnasy commented Oct 29, 2024

It's the same error with ctx.rewrite.

@ematipico ematipico linked a pull request Oct 30, 2024 that will close this issue
@ematipico ematipico linked a pull request Oct 31, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: nice to have Not breaking anything but nice to have (priority) feat: routing Related to Astro routing (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants