fix(website): prefix astrochart.js path with BASE_URL#112
Merged
Conversation
The deploy workflow ran the library build (webpack, Node 20) and the Astro website build in the same job under node-version 20, causing Astro to fail with "Node.js v20 is not supported". A single job can only run one Node version, so split the build job: - build-library (Node 20): builds the webpack bundle and uploads it as a GitHub Actions artifact - build-website (Node 22): downloads the bundle, copies it into website/public/, installs website deps, builds the Astro site, and uploads the Pages artifact - deploy: now depends on build-website (unchanged otherwise) 🤖 Generated with [eca](https://eca.dev) Co-Authored-By: eca <git@eca.dev>
The bundle was hard-coded as '/astrochart.js' (root-relative) in ChartDemo.astro. With base: '/AstroChart' in astro.config.mjs the file is deployed at /AstroChart/astrochart.js, so the browser was requesting the wrong path and getting a 404. Pass import.meta.env.BASE_URL into the is:inline script via define:vars and prefix both the querySelector guard and the dynamic script.src with it. Astro guarantees BASE_URL ends with '/', so concatenating 'astrochart.js' produces the correct path. 🤖 Generated with [eca](https://eca.dev) Co-Authored-By: eca <git@eca.dev>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ChartDemo.astrohard-coded the bundle path as/astrochart.js(root-relative)base: '/AstroChart'set inastro.config.mjs, the file is actually deployed at/AstroChart/astrochart.jshttps://astrodraw.github.io/astrochart.js→ 404Fix
Pass
import.meta.env.BASE_URLinto theis:inlinescript viadefine:varsand prefix both usages with it:Astro guarantees
BASE_URLends with/, so concatenation produces the correct path without any extra slashes.Test plan
astrochart.jsin the browser network tabChartDemoinstances on the same page still deduplicate the bundle load correctly🤖 Generated with eca