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

Serving static files via hono on bun kills the prerenderer #28910

Open
1 task
heddendorp opened this issue Nov 20, 2024 · 5 comments
Open
1 task

Serving static files via hono on bun kills the prerenderer #28910

heddendorp opened this issue Nov 20, 2024 · 5 comments
Assignees
Labels
angular/build:application needs: more info Reporter must clarify the issue

Comments

@heddendorp
Copy link

Command

build

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

I wanted to use the new hybrid rendering with hono and bun.
Everything seems to work mostly fine until I try to serve static files from my server. This kills my build process as the route extraction fails.
As long as the static serving is commented out, the build is fine and works with bun and the dev server.

Minimal Reproduction

I have a repro here https://github.com/heddendorp/ssr-bun-issue
Cloning, running bun install and bun run build will give you the error.
You can get rid of this line https://github.com/heddendorp/ssr-bun-issue/blob/4492a605afff2829b28274c0e09c6ef0ec3c1901/projects/app/src/server.ts#L46 to make the build work.

Exception or Error

Prerendered 0 static routes.
Application bundle generation failed. [3.477 seconds]

✘ [ERROR] An error occurred while extracting routes.

Error: No handler function exported from C:\Users\hedde\code\evorto\node_modules\@angular\build\src\utils\server-rendering\routes-extractor-worker.js
    at [...]node_modules\piscina\dist\worker.js:142:23

Your Environment

Angular CLI: 19.0.0
Node: 22.4.0
Package Manager: bun 1.1.36
OS: win32 x64

Angular: 19.0.0
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, platform-server
... router, ssr

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1900.0
@angular-devkit/build-angular   19.0.0
@angular-devkit/core            19.0.0
@angular-devkit/schematics      19.0.0
@schematics/angular             19.0.0
rxjs                            7.8.1
typescript                      5.6.3
zone.js                         0.15.0

Anything else relevant?

I'm happy to provide more context to clear this up

@alan-agius4
Copy link
Collaborator

alan-agius4 commented Nov 20, 2024

Are you using bun as your runtime, or are you using Node.js? If it's the latter, import { serveStatic } from 'hono/bun' will not be valid.

Unfortunately, piscina is intercepting all errors during the initialization phase. https://github.com/piscinajs/piscina/blob/b64747233446ca4271e6aed744a740f637e278a5/src/worker.ts#L57

@alan-agius4 alan-agius4 added needs: more info Reporter must clarify the issue and removed type: bug/fix labels Nov 20, 2024
@heddendorp
Copy link
Author

heddendorp commented Nov 21, 2024

I am importing import { serveStatic } from 'hono/bun' and would think that I am using bun as a runtime (running bun run build).
How do I make sure that bun is running the build, I was thinking that it is more nody.
Edit: sorry for taking down the repo again, I underestimated what else came in other branches there 😅
I can create a new one tomorrow.

@alan-agius4
Copy link
Collaborator

It seems that you're using Bun as a package manager rather than as a runtime, which are two distinct tools.

To learn more about installing Bun as a runtime, check out the official documentation here: Bun Installation Guide.

@heddendorp
Copy link
Author

Hey @alan-agius4 I did install bun and could also execute the built server with it.
The issue seems to only arise when running bun run build. I'm not sure how to influence the prerendering runtime that is used by angular during the build.
Sorry for my ignorance, I'll try to get a repo up that reproduces the issue, maybe that is more helpful.

@alan-agius4
Copy link
Collaborator

alan-agius4 commented Nov 21, 2024

Can you update please update node_modules/@angular/build/src/utils/server-rendering/routes-extractor-worker.js to below and report back with the error you are seeing?

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const worker_threads_1 = require("worker_threads");
const schema_1 = require("../../builders/application/schema");
const fetch_patch_1 = require("./fetch-patch");
const launch_server_1 = require("./launch-server");
const load_esm_from_memory_1 = require("./load-esm-from-memory");
/**
 * This is passed as workerData when setting up the worker via the `piscina` package.
 */
const { outputMode, hasSsrEntry } = worker_threads_1.workerData;
let serverURL = launch_server_1.DEFAULT_URL;
/** Renders an application based on a provided options. */
async function extractRoutes() {
    if (outputMode !== undefined && hasSsrEntry) {
      serverURL = await (0, launch_server_1.launchServer)();
    }
    (0, fetch_patch_1.patchFetchToLoadInMemoryAssets)(serverURL);

    const { ɵextractRoutesAndCreateRouteTree: extractRoutesAndCreateRouteTree } = await (0, load_esm_from_memory_1.loadEsmModuleFromMemory)('./main.server.mjs');
    const { routeTree, appShellRoute, errors } = await extractRoutesAndCreateRouteTree(serverURL, undefined /** manifest */, true /** invokeGetPrerenderParams */, outputMode === schema_1.OutputMode.Server /** includePrerenderFallbackRoutes */);
    return {
        errors,
        appShellRoute,
        serializedRouteTree: routeTree.toObject(),
    };
}
exports.default = extractRoutes;

@alan-agius4 alan-agius4 self-assigned this Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
angular/build:application needs: more info Reporter must clarify the issue
Projects
None yet
Development

No branches or pull requests

3 participants