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 'ASTRO_VERSION' before initialization #261

Closed
1 task
zanhk opened this issue May 12, 2024 · 19 comments
Closed
1 task

Cannot access 'ASTRO_VERSION' before initialization #261

zanhk opened this issue May 12, 2024 · 19 comments
Labels
- P4: important Violate documented behavior or significantly improves performance (priority) pkg: cloudflare upstream

Comments

@zanhk
Copy link

zanhk commented May 12, 2024

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.
@zanhk
Copy link
Author

zanhk commented May 12, 2024

Also with version 10.2.4 I don't have the problem but I encounter it only with version 10.2.6

@zanhk
Copy link
Author

zanhk commented May 12, 2024

10.2.5 works as well

@zanhk
Copy link
Author

zanhk commented May 12, 2024

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();
		}
	}
};

de6f3eb#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"
	}
}

@zanhk
Copy link
Author

zanhk commented May 12, 2024

Will probably have to test the exact version of each package to find the cause

image

@zanhk
Copy link
Author

zanhk commented May 12, 2024

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

@zanhk
Copy link
Author

zanhk commented May 12, 2024

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"

@alexanderniebuhr alexanderniebuhr added pkg: cloudflare needs repro Issue needs a reproduction labels May 12, 2024
@alexanderniebuhr
Copy link
Member

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.

@zanhk
Copy link
Author

zanhk commented May 12, 2024

Ok, I think it's a problem with some other integration but I ll make some tests

@mantis
Copy link

mantis commented May 25, 2024

@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

@zanhk
Copy link
Author

zanhk commented May 26, 2024

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

@alexanderniebuhr
Copy link
Member

@zanhk Thanks for finding this out. Now we know that it relates to the markdoc integration. Going to try and find a fix soon.

@alexanderniebuhr alexanderniebuhr added - P4: important Violate documented behavior or significantly improves performance (priority) and removed needs repro Issue needs a reproduction labels May 26, 2024
@alexanderniebuhr
Copy link
Member

alexanderniebuhr commented May 27, 2024

@zanhk #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 🤔

@zanhk
Copy link
Author

zanhk commented May 27, 2024

Thanks @alexanderniebuhr, If you push this version to npm (0.0.0-xxx) I will make some tests

@q1b
Copy link

q1b commented Jun 7, 2024

I am facing same issue, have you found some work around this @zanhk

@alexanderniebuhr
Copy link
Member

I'm hoping that once the upstream bug (withastro/astro#10738) is fixed, we can fix this one too.

@zanhk
Copy link
Author

zanhk commented Jun 7, 2024

@q1b Right now I m using this versions

 "@astrojs/cloudflare": "0.0.0-cf-deps-chunk-20240407075425",
"astro": "4.7.0",

@alexanderniebuhr
Copy link
Member

This should be fixed in the v11 release, which will be published later today to npm.

@zanhk
Copy link
Author

zanhk commented Jun 22, 2024

Awesome!

@N0N4M3BNS
Copy link

[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",

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 upstream
Projects
None yet
Development

No branches or pull requests

5 participants