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

output: "hybrid" fails to show 404 page. #9615

Closed
1 task done
disrae opened this issue Jan 4, 2024 · 16 comments · Fixed by #9648
Closed
1 task done

output: "hybrid" fails to show 404 page. #9615

disrae opened this issue Jan 4, 2024 · 16 comments · Fixed by #9648
Labels
feat: error pages Related to 404 and 500 handling (scope) needs repro Issue needs a reproduction needs triage Issue needs to be triaged

Comments

@disrae
Copy link

disrae commented Jan 4, 2024

Astro Info

Astro                    v4.0.6
Node                     v20.8.0
System                   macOS (arm64)
Package Manager          npm
Output                   hybrid
Adapter                  @astrojs/vercel/serverless
Integrations             @astrojs/tailwind
                         @astrojs/mdx
                         @astrojs/sitemap
                         @storyblok/astro

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

No response

Describe the Bug

When using hybrid rendering, if I push my .vercel/ directory to the repo the 404 page function does not work.
404 with:
✅ Static rendering
✅ Hybrid localhost with 404 as function or static
❌ Hybrid on Vercel with 404 as function or static returns 500 error

500 error:

2024-01-04T23:28:32.305Z	undefined	ERROR	Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/var/task/dist/entry.mjs' imported from /var/task/___vc/__launcher/bridge-server-72TT5FOD.js
    at new NodeError (node:internal/errors:406:5)
    at finalizeResolution (node:internal/modules/esm/resolve:238:11)
    at moduleResolve (node:internal/modules/esm/resolve:850:10)
    at moduleResolveWithNodePath (node:internal/modules/esm/resolve:972:12)
    at defaultResolve (node:internal/modules/esm/resolve:1091:79)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:383:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:352:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:228:38)
    at ModuleLoader.import (node:internal/modules/esm/loader:315:34)
    at importModuleDynamically (node:internal/modules/cjs/loader:1164:37) {
  url: 'file:///var/task/dist/entry.mjs',
  code: 'ERR_MODULE_NOT_FOUND'
}

### Documentation Followed
https://docs.astro.build/en/guides/server-side-rendering/#add-an-adapter
https://docs.astro.build/en/guides/server-side-rendering/#opting-out-of-pre-rendering-in-hybrid-mode

INIT_REPORT Init Duration: 187.44 ms	Phase: init	Status: error	Error Type: Runtime.ExitError
2024-01-04T23:28:32.552Z	undefined	ERROR	Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/var/task/dist/entry.mjs' imported from /var/task/___vc/__launcher/bridge-server-72TT5FOD.js
    at new NodeError (node:internal/errors:406:5)
    at finalizeResolution (node:internal/modules/esm/resolve:238:11)
    at moduleResolve (node:internal/modules/esm/resolve:850:10)
    at moduleResolveWithNodePath (node:internal/modules/esm/resolve:972:12)
    at defaultResolve (node:internal/modules/esm/resolve:1091:79)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:383:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:352:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:228:38)
    at ModuleLoader.import (node:internal/modules/esm/loader:315:34)
    at importModuleDynamically (node:internal/modules/cjs/loader:1164:37) {
  url: 'file:///var/task/dist/entry.mjs',
  code: 'ERR_MODULE_NOT_FOUND'
}
INIT_REPORT Init Duration: 211.74 ms	Phase: invoke	Status: error	Error Type: Runtime.ExitError
Error: Runtime exited with error: exit status 1

What's the expected result?

Expected 404 serverless function to return the 404 page.
https://docs.astro.build/en/guides/server-side-rendering/#add-an-adapter
https://docs.astro.build/en/guides/server-side-rendering/#opting-out-of-pre-rendering-in-hybrid-mode

Link to Minimal Reproducible Example

https://goose-website-cbarwkiun-goose-insurance-1c431eed.vercel.app/en-us/should-go-to-404

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 4, 2024
@lilnasy lilnasy added the needs repro Issue needs a reproduction label Jan 5, 2024
Copy link
Contributor

github-actions bot commented Jan 5, 2024

Hello @disrae. 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 Jan 5, 2024
@lilnasy
Copy link
Contributor

lilnasy commented Jan 5, 2024

This seems like an important issue. However, we can't investigate without a simple project to debug and try fixes on.

@disrae
Copy link
Author

disrae commented Jan 5, 2024

Okay I will do, however the repro will have to be deployed on vercel for it to cause the issue.

@lilnasy lilnasy mentioned this issue Jan 5, 2024
@lilnasy
Copy link
Contributor

lilnasy commented Jan 5, 2024

@disrae could you try with npm install @astrojs/vercel@experimental--9624?

@disrae
Copy link
Author

disrae commented Jan 5, 2024

Hmm, it works in the new project, let me try upgrading astro from 4.0.6 to 4.1 or to your version.
Reproduction repo
site, which works, not much to see here

Could there be some kind of build cache on Vercel that I need to clear?

@disrae
Copy link
Author

disrae commented Jan 5, 2024

This seems like the reproduction is a production deploy?
image

Also, the issue happens on vercel in preview deploys.

@lilnasy
Copy link
Contributor

lilnasy commented Jan 5, 2024

Yeah, I noticed from the URL - it isn't the same issue I ran into earlier.

Your old project (linked in the issue description) responds with a 500. What do the logs say?

@disrae
Copy link
Author

disrae commented Jan 5, 2024

one second... reproducing....

@disrae
Copy link
Author

disrae commented Jan 5, 2024

Okay, upon re-reproducing in the main project, the patch version for the vercel adapter incremented by 2, and the issue seems to be gone!

@disrae
Copy link
Author

disrae commented Jan 5, 2024

Latest Vercel adapter package seems to have solved the issue.
"@astrojs/vercel": "^6.1.2"

@disrae disrae closed this as completed Jan 5, 2024
@disrae disrae reopened this Jan 5, 2024
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jan 5, 2024
@disrae
Copy link
Author

disrae commented Jan 5, 2024

Okay, it is not solved. The bug happens when I commit the files from the .vercel directory, without it it still works, and I'm getting the logs as well, which is the only reason I am using hybrid mode, to see which pages are missing redirects, aka 404ing.
image

@lilnasy
Copy link
Contributor

lilnasy commented Jan 5, 2024

Is the result any different when using the vercel CLI?

pnpm exec astro build
pnpm exec vercel deploy --prebuilt --prod

@disrae
Copy link
Author

disrae commented Jan 5, 2024

Sorry bogged down, but trying to get to that.

@disrae
Copy link
Author

disrae commented Jan 6, 2024

vercel deploy gave me some trouble, said I didn't have a project by the name, despite being in the correct account and such, then it seemed to not automatically know it was an Astro project and the defaults it was presenting didn't seem right, so I backed out.
I did however manage to reproduce the issue by pushing the .vercel/ directory, is that directory meant to be strictly local?

Reproduction:
repo
demo
logs:

2024-01-06T01:16:20.477Z	undefined	ERROR	Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/var/task/dist/entry.mjs' imported from /var/task/___vc/__launcher/bridge-server-72TT5FOD.js
    at new NodeError (node:internal/errors:406:5)
    at finalizeResolution (node:internal/modules/esm/resolve:238:11)
    at moduleResolve (node:internal/modules/esm/resolve:850:10)
    at moduleResolveWithNodePath (node:internal/modules/esm/resolve:972:12)
    at defaultResolve (node:internal/modules/esm/resolve:1091:79)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:383:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:352:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:228:38)
    at ModuleLoader.import (node:internal/modules/esm/loader:315:34)
    at importModuleDynamically (node:internal/modules/cjs/loader:1164:37) {
  url: 'file:///var/task/dist/entry.mjs',
  code: 'ERR_MODULE_NOT_FOUND'
}
INIT_REPORT Init Duration: 191.03 ms	Phase: init	Status: error	Error Type: Runtime.ExitError
2024-01-06T01:16:20.703Z	undefined	ERROR	Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/var/task/dist/entry.mjs' imported from /var/task/___vc/__launcher/bridge-server-72TT5FOD.js
    at new NodeError (node:internal/errors:406:5)
    at finalizeResolution (node:internal/modules/esm/resolve:238:11)
    at moduleResolve (node:internal/modules/esm/resolve:850:10)
    at moduleResolveWithNodePath (node:internal/modules/esm/resolve:972:12)
    at defaultResolve (node:internal/modules/esm/resolve:1091:79)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:383:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:352:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:228:38)
    at ModuleLoader.import (node:internal/modules/esm/loader:315:34)
    at importModuleDynamically (node:internal/modules/cjs/loader:1164:37) {
  url: 'file:///var/task/dist/entry.mjs',
  code: 'ERR_MODULE_NOT_FOUND'
}
INIT_REPORT Init Duration: 214.27 ms	Phase: invoke	Status: error	Error Type: Runtime.ExitError
Error: Runtime exited with error: exit status 1

image
image

@lilnasy
Copy link
Contributor

lilnasy commented Jan 8, 2024

From the error message, I can tell that vercel's platform is looking at wrong place. No astro code has run before that error occurs.

It might be because install/build/start commands are set to a wrong preset in the project config. Can you try again by deploying to a new project?

@lilnasy
Copy link
Contributor

lilnasy commented Jan 8, 2024

Nothing wrong with your example itself. https://repro-9615.vercel.app

astro build image
vercel deploy image

@lilnasy lilnasy closed this as completed Jan 8, 2024
@lilnasy lilnasy reopened this Jan 8, 2024
@natemoo-re natemoo-re added the feat: error pages Related to 404 and 500 handling (scope) label Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: error pages Related to 404 and 500 handling (scope) needs repro Issue needs a reproduction needs triage Issue needs to be triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants