-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
In 4.16.14: middleware suddenly reads config.ts with astro build
, it didn't since at least 4.10
#12527
Comments
astro build
fails with ENOEND in pipeline.js:105:57astro build
fails with ENOENT in pipeline.js:105:57
That file config.ts is read in the middleware, and the middleware is also executed during the build for prerendered pages. It's documented in documentation. It's been like this since the very beginning. Can you please narrow down the issue and provide a reproduction? |
Hello @corneliusroemer. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with |
I agree that the reproduction isn't minimal but it is a precise reproduction occurring between to patch versions. You can clone it in 30s, npm install and there you go. Minimizing a TS app isn't easy. If the reason is that "the middleware is also executed during the build for prerendered pages. It's documented in documentation." this must mean that in a patch version, some new pages prerendered that didn't before. Is that possible? |
Ok, it does seem to happen in the middleware and we had a code change there 6 days ago. So it's possible this should have always been an error and it just wasn't in the particular Astro version we were using at the time, likely 4.16.7 Does that sound like a plausible explanation? It sounds similar to this issue? #12495 |
Ok here's a stackblitz: it passes with 4.16.13 and fails with 4.16.14 when you run It's got only tiny modifications compared to the stackblitz from #12495: reading a file that doesn't exist in config.ts - this wasn't an issue till 4.16.14 Builds with 4.14, builds with 4.10, so if it the behavior now is how it should be it hasn't been correct for a long time. |
astro build
fails with ENOENT in pipeline.js:105:57astro build
, it didn't since at least 4.10
The stackblitz you shared uses In the latest patch, we fixed a minor bug around the middleware, so maybe, without knowing, you were leveraging the bug? |
Currently, it seems that all code must be defined within onRequest. In my case I have something like connecting with an another system through a socket file. I don't know if it will be helpful, but I will list the patch that I have applied at hand. This is for [email protected]. diff --git a/node_modules/astro/dist/core/build/pipeline.js b/node_modules/astro/dist/core/build/pipeline.js
index a960ded..1accc2f 100644
--- a/node_modules/astro/dist/core/build/pipeline.js
+++ b/node_modules/astro/dist/core/build/pipeline.js
@@ -12,7 +12,7 @@ import { createDefaultRoutes } from "../routing/default.js";
import { findRouteToRewrite } from "../routing/rewrite.js";
import { isServerLikeOutput } from "../util.js";
import { getOutDirWithinCwd } from "./common.js";
-import { cssOrder, getPageData, mergeInlineCss } from "./internal.js";
+import { cssOrder, getPageData, mergeInlineCss, hasPrerenderedPages } from "./internal.js";
import { ASTRO_PAGE_MODULE_ID, ASTRO_PAGE_RESOLVED_MODULE_ID } from "./plugins/plugin-pages.js";
import { RESOLVED_SPLIT_MODULE_ID } from "./plugins/plugin-ssr.js";
import { getPagesFromVirtualModulePageName, getVirtualModulePageName } from "./plugins/util.js";
@@ -102,7 +102,8 @@ class BuildPipeline extends Pipeline {
}
const renderersEntryUrl = new URL(`renderers.mjs?time=${Date.now()}`, baseDirectory);
const renderers = await import(renderersEntryUrl.toString());
- const middleware = internals.middlewareEntryPoint ? await import(internals.middlewareEntryPoint.toString()).then((mod) => {
+ // Probably it would be OK to import internals.middlewareEntryPoint only if there are prerendered pages.
+ const middleware = hasPrerenderedPages(internals) && internals.middlewareEntryPoint ? await import(internals.middlewareEntryPoint.toString()).then((mod) => {
return function() {
return { onRequest: mod.onRequest };
}; Note: I created this patch because I have only recently started using astro and have not yet fully understood it. |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
When upgrading from 4.16.14 (via dependabot),
astro build
suddenly fails, it worked fine in 4.16.13.We have a JSON config file that is read by config.ts at runtime. It's not present at build time. This was never an issue until 4.16.14 where we suddenly get build failures if the file is not present (no build failure if the file is present).
Repro:
cd website && npm ci && npm run build
This previous commit with only difference being 4.16.13 builds fine: loculus-project/loculus@94732ca
Stacktrace:
What's the expected result?
Build works without issue as it did until 4.16.13
Link to Minimal Reproducible Example
loculus-project/loculus@7534e92
Participation
The text was updated successfully, but these errors were encountered: