-
Couldn't load subscription status.
- Fork 71
Description
Apologies for my incompleteness, here, I was in a rush. There were some more issues (I will reiterate the complete list here):
1. Fatal Installation & Dependency Bugs
The npm install command fails immediately due to several conflicts in the package.json file.
ERESOLVEConflict (Astro 4 vs. Astro 5): Thepackage.jsonlistsastro@latest(Astro 5) but also includes older packages like@astrojs/vue@^4.5.0that have a peer dependency on Astro 4. This creates a fatalERESOLVEerror.ETARGETError (BrokennodeDependency): Thepackage.jsonincorrectly listsnodeas an npm dependency. This causesnpm installto fail with anETARGETerror as it tries to download a non-existent Node.js binary.- Adapter Conflict: The
package.jsonincludes both@astrojs/netlifyand@astrojs/vercel, which are mutually exclusive.
2. Configuration Bugs
After fixing the dependency issues, the server still fails to start due to errors in the astro.config.mjs file.
- Missing Module Error: The config file imports
@astrojs/vercel/serverlessat the top, even if the user uninstalls the Vercel package. This causes aCannot find modulecrash. - Broken Logic: The
adapterlogic is conditional on an environment variable (env.NETLIFY), but this doesn't account for the Vercel import still being present.
3. Runtime & Code Bugs
After fixing the install and config, the dev server crashes when trying to render pages.
- CSS Syntax Error:
Header.astrohas an@applyrule nested inside an@screenrule, which is invalid syntax and breaks the build. - Multiple "Cannot read properties of undefined (reading 'data')" Crashes: The
src/pages/tag/[...page].astrofile is highly prone to crashing:- It tries to
.sort()posts fromgetCollection("blog")before filtering out invalid posts (e.g., drafts with nopubDate). - It tries to
.map()posts to find tags before filtering out invalid posts. - It tries to destructure
datafromgetEntry("config", "blog")without checking if the entry was found first. - The
getStaticPathsfunction returns an empty array if no posts have tags, which causes the main component to crash because thepageprop isundefined.
- It tries to
4. Cache Corruption
- Finally, after fixing all of the above, the dev server's cache is often corrupted from the previous crashes, leading to "ghost" errors like
Cannot find module '@layouts/PageLayout.js'(looking for a.jsfile instead of.astro). This requires a fullrm -rf node_modulesto fix.
Summary of Fixes
To get the project running, I had to:
- Edit
package.jsonto remove thenodedependency. - Edit
astro.config.mjsto remove all Vercel imports and hard-code the Netlify adapter. - Run
rm -rf node_modules package-lock.json. - Run
npm uninstall @astrojs/vercel. - Run
npm install @astrojs/vue@latest ...(and all other@astrojspackages) to force them to update to Astro 5-compatible versions. - Run
npm installto get the remaining packages. - Manually add safety checks (e.g.,
.filter(post => post && post.data)) intag/[...page].astroto prevent the runtime crashes.
5. Root Cause & Solution
The core issue is that this project is "unlocked," allowing new package versions to break the build. The package-lock.json in the repo is simply a little "rotten" and just needs to be locked down to protect from deprecations/ERESOLVE/ETARGET fatalities.
Solution: After all the dependencies are fixed, the new, working package-lock.json file must be committed to the repo. This will "lock in" the working state (Astro 5, the new Vue, etc.) and ensure that all new users get a reproducible, working build.
Hopefully, this helps save the next person some time! Thanks.