Cannot access 'ASTRO_VERSION' before initialization
Astro Info
Astro v4.8.2
Node v20.12.2
System Windows (x64)
Package Manager unknown
Output hybrid
Adapter @astrojs/cloudflare
Integrations @astrojs/alpinejs
@astrojs/tailwind
@astrojs/sitemap
astro-icon
@astrojs/react
@astrojs/markdoc
@vite-pwa/astro-integration
Describe the Bug
Cannot access 'ASTRO_VERSION' before initialization
Stack trace:
at createAstro (file:///D:/repositories/majestico/antares/dist/_worker.js/chunks/astro_BR22DijI.mjs:1536:26)
at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
at async BuildPipeline.retrieveManifest (file:///D:/repositories/majestico/antares/node_modules/astro/dist/core/build/pipeline.js:93:26)
at async staticBuild (file:///D:/repositories/majestico/antares/node_modules/astro/dist/core/build/static-build.js:108:7)
at async AstroBuilder.run (file:///D:/repositories/majestico/antares/node_modules/astro/dist/core/build/index.js:164:7)
at async build (file:///D:/repositories/majestico/antares/node_modules/astro/dist/cli/build/index.js:20:3)
at async cli (file:///D:/repositories/majestico/antares/node_modules/astro/dist/cli/index.js:168:5)
error: script "build" exited with code 1
function createAstro(site) {
return {
// TODO: this is no longer necessary for `Astro.site`
// but it somehow allows working around caching issues in content collections for some tests
site: new URL(site) ,
generator: `Astro v${ASTRO_VERSION}`,
glob: createAstroGlobFn()
};
}
What's the expected result?
It's probably a problem with some other integration but commeting
adapter: cloudflare({
imageService: "compile",
}),
seem to avoid the problem, just wanna ask if it's happened to someone else.
Thanks
Link to Minimal Reproducible Example
This problem happen specifically on cloudflare so I cannot reproduce on stackblitz or others
Participation
- [ ] I am willing to submit a pull request for this issue.
Also with version 10.2.4 I don't have the problem but I encounter it only with version 10.2.6
10.2.5 works as well
Commeting this fix the problem
vite.build.rollupOptions.output.manualChunks = (id) => {
if (id.includes("node_modules")) {
if (id.indexOf("node_modules") !== -1) {
// const basic = id.toString().split('node_modules/')[1];
// const sub1 = basic.split('/')[0];
// if (sub1 !== '.pnpm') {
// return sub1.toString();
// }
// const name2 = basic.split('/')[1];
// return name2.split('@')[name2[0] === '@' ? 1 : 0].toString();
}
}
};
https://github.com/withastro/adapters/commit/de6f3eba4ad4135fd762320b1219850ba9b3d7e9#diff-1d2a2b56ad20e7e5b13936929d10bebf30d56ffa7cdc64f686dff4ae6cfafb60R266
But now I have the problem that this commit was trying to address, I tried with astro version 4.8.2 and 4.7.0
It could be that one of that manualChucks is trigger the problem
{
"dependencies": {
"@astrojs/alpinejs": "^0.4.0",
"@astrojs/cloudflare": "^10.2.6",
"@astrojs/markdoc": "^0.11.0",
"@astrojs/react": "^3.3.4",
"@astrojs/rss": "^4.0.5",
"@astrojs/sitemap": "^3.1.4",
"@astrojs/tailwind": "^5.1.0",
"@cloudflare/pages-plugin-mailchannels": "^0.1.4",
"@keystatic/astro": "^5.0.0",
"@keystatic/core": "^0.5.14",
"alpinejs": "^3.13.10",
"astro": "4.7.0",
"gsap": "npm:@gsap/business@^3.12.5",
"react": "^18.3.1",
"react-colorful": "^5.6.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@astrolib/seo": "1.0.0-beta.5",
"@biomejs/biome": "1.7.3",
"@bobthered/tailwindcss-palette-generator": "^3.2.3",
"@cloudflare/workers-types": "^4.20240502.0",
"@iconify-json/ic": "^1.1.17",
"@iconify-json/mdi": "^1.1.66",
"@iconify-json/ph": "^1.1.13",
"@iconify-json/solar": "^1.1.9",
"@tailwindcss/aspect-ratio": "^0.4.2",
"@tailwindcss/forms": "^0.5.7",
"@tailwindcss/typography": "^0.5.13",
"@types/alpinejs": "^3.13.10",
"@types/react": "^18.3.2",
"@types/react-dom": "^18.3.0",
"@vite-pwa/assets-generator": "^0.2.4",
"@vite-pwa/astro": "^0.4.0",
"astro-icon": "^1.1.0",
"sharp": "0.33.3",
"tailwindcss": "^3.4.3",
"workbox-window": "^7.1.0"
}
}
Will probably have to test the exact version of each package to find the cause
Rolling back astro to 4.7.0 seem to fix the chuck issue for @astrojs/cloudflare:10.2.4
For the version 10.2.6 I don't know the possible cause of the problem
For anyone having the same problem here my full package version that works
{
"dependencies": {
"@astrojs/alpinejs": "^0.4.0",
"@astrojs/cloudflare": "10.2.4",
"@astrojs/markdoc": "^0.11.0",
"@astrojs/react": "3.3.1",
"@astrojs/rss": "^4.0.5",
"@astrojs/sitemap": "^3.1.4",
"@astrojs/tailwind": "^5.1.0",
"@cloudflare/pages-plugin-mailchannels": "0.1.4",
"@keystatic/astro": "^5.0.0",
"@keystatic/core": "0.5.14",
"alpinejs": "^3.13.10",
"astro": "4.7.0",
"gsap": "npm:@gsap/business@^3.12.5",
"react": "^18.3.1",
"react-colorful": "^5.6.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@astrolib/seo": "1.0.0-beta.5",
"@biomejs/biome": "1.7.3",
"@bobthered/tailwindcss-palette-generator": "^3.2.3",
"@cloudflare/workers-types": "4.20240502.0",
"@iconify-json/ic": "^1.1.17",
"@iconify-json/mdi": "^1.1.66",
"@iconify-json/ph": "1.1.13",
"@iconify-json/solar": "^1.1.9",
"@tailwindcss/aspect-ratio": "^0.4.2",
"@tailwindcss/forms": "^0.5.7",
"@tailwindcss/typography": "^0.5.13",
"@types/alpinejs": "^3.13.10",
"@types/react": "18.3.2",
"@types/react-dom": "^18.3.0",
"@vite-pwa/assets-generator": "^0.2.4",
"@vite-pwa/astro": "^0.4.0",
"astro-icon": "^1.1.0",
"sharp": "0.33.3",
"tailwindcss": "^3.4.3",
"workbox-window": "^7.1.0"
}
}
Essentially
"@astrojs/cloudflare": "10.2.4" and "astro": "4.7.0"
Thanks for submitting this issue. Can you please provide a minimal reproduction, even if it only occurs on Cloudflare. We can always clone the code and rung wrangler pages dev ourselves.
Ok, I think it's a problem with some other integration but I ll make some tests
@alexanderniebuhr I just stumbled across this against a public repo - if I take https://github.com/IdealProject/ideal ; which currently uses 9.2.1 and update to 10.X, it gives the same ASTRO_VERSION error
After multiple tries I found how to reproduce the problem consistenly, the problem happen with the markdoc integration when there is at least a mdoc item in the collection, also it happen only with the latest versions of the cloudflare integration,
google_screen_recording_2024-05-26T13-16_42.903Z.webm
Here the repo I used to test this: https://github.com/zanhk/cannot-access-astro-version, I made it as minimal as possible
@zanhk Thanks for finding this out. Now we know that it relates to the markdoc integration. Going to try and find a fix soon.
@zanhk https://github.com/withastro/adapters/pull/270 will most likely fix the issue, however that solution is a workaround which we most likely won't be able to get into production soon.. We're still trying to figure out the best way to do it 🤔
Thanks @alexanderniebuhr, If you push this version to npm (0.0.0-xxx) I will make some tests
I am facing same issue, have you found some work around this @zanhk
I'm hoping that once the upstream bug (https://github.com/withastro/astro/pull/10738) is fixed, we can fix this one too.
@q1b Right now I m using this versions
"@astrojs/cloudflare": "0.0.0-cf-deps-chunk-20240407075425",
"astro": "4.7.0",
This should be fixed in the v11 release, which will be published later today to npm.
Awesome!
[ERROR] ReferenceError: Cannot access 'page' before initialization I have this issues so how to fix it?
"astro": "^4.16.7", "@astrojs/cloudflare": "^11.2.0",