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

Cannot access 'SITE_TITLE' before initialization during build in 2.0.0-beta.0 #5754

Closed
1 task
fflaten opened this issue Jan 4, 2023 · 7 comments · Fixed by #5822
Closed
1 task

Cannot access 'SITE_TITLE' before initialization during build in 2.0.0-beta.0 #5754

fflaten opened this issue Jan 4, 2023 · 7 comments · Fixed by #5822
Assignees
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority)

Comments

@fflaten
Copy link
Contributor

fflaten commented Jan 4, 2023

What version of astro are you using?

2.0.0-beta.0

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

npm

What operating system are you using?

Linux

Describe the Bug

Getting the following error when building (not dev) using 2.0.0-beta.0. Works fine in 1.9.0.

generating static routes 
 error   Cannot access 'SITE_TITLE' before initialization
  File:
    file://file:///home/projects/github-zea7ll/node_modules/astro/dist/core/build/generate.js:81:20
  Stacktrace:
Error: Cannot access 'SITE_TITLE' before initialization
    at async Module.generatePages (file://file:///home/projects/github-zea7ll/node_modules/astro/dist/core/build/generate.js:81:20)
    at async Module.staticBuild (file://file:///home/projects/github-zea7ll/node_modules/astro/dist/core/build/static-build.js:85:7)
    at async AstroBuilder.build (file://file:///home/projects/github-zea7ll/node_modules/astro/dist/core/build/index.js:103:5)

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-zea7ll

Participation

  • I am willing to submit a pull request for this issue.
@fflaten
Copy link
Contributor Author

fflaten commented Jan 4, 2023

Sorry for the vague issue and weird repro. It's taken hours to extract enough to create the repro so I need a break before trying to simplify it more. Code getting bundled in the wrong order?

@matthewp
Copy link
Contributor

matthewp commented Jan 4, 2023

Does this happen in 1.x?

@fflaten
Copy link
Contributor Author

fflaten commented Jan 4, 2023

No, works fine in 1.9.0.

@natemoo-re
Copy link
Member

natemoo-re commented Jan 4, 2023

Just FYI @matthewp this looks like something related to the way our intermediate (server) bundle is generated before the pages are statically rendered. You can see this in the reproduction by inspecting the files in the dist/ directory before the error occurs. The constants are re-exported from the index page chunk, which seems to be the source of the problem.

I suspect this would happen on 1.x with the --experimental-prerender flag passed

@fflaten
Copy link
Contributor Author

fflaten commented Jan 4, 2023

I suspect this would happen on 1.x with the --experimental-prerender flag passed

Can confirm 1.9.0 breaks with astro build --experimental-prerender in the new simplified repro: https://stackblitz.com/edit/github-zea7ll-jop67q (which is currently set to 2.0.0-beta.0)

@natemoo-re natemoo-re self-assigned this Jan 4, 2023
@natemoo-re
Copy link
Member

Thanks for your patience, I'm looking into this one again today. Will be sure to share progress updates.

@matthewp matthewp added the - P4: important Violate documented behavior or significantly impacts performance (priority) label Jan 9, 2023
@natemoo-re
Copy link
Member

I was able to determine what bundling change causes this, but I'm still unsure of the correct way to split each page into a chunk without hitting this issue.

That being said, per-page splitting is purely cosmetic. If we emit a single chunk, this is no longer an issue.

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 impacts performance (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants