Skip to content

ClientEntry not found issues when changing base path #3666

@CodingFlow

Description

@CodingFlow

When changing base path from root, the client-entry file cannot be found, returns 404 error, when visiting the page in the browser in dev mode. In production build, client-entry is found, but stylesheet imported by client-entry is not found.

Steps to Reproduce

  1. Create new Fresh project:
deno run -Ar jsr:@fresh/init
  1. Change base path in main.ts and vite.config.ts:

main.ts

import { App, staticFiles } from "fresh";
import { define, type State } from "./utils.ts";

export const app = new App<State>({
  basePath: "/ui"
});

app.use(staticFiles());

// Pass a shared value from a middleware
app.use(async (ctx) => {
  ctx.state.shared = "hello";
  return await ctx.next();
});

// this is the same as the /api/:name route defined via a file. feel free to delete this!
app.get("/api2/:name", (ctx) => {
  const name = ctx.params.name;
  return new Response(
    `Hello, ${name.charAt(0).toUpperCase() + name.slice(1)}!`,
  );
});

// this can also be defined via a file. feel free to delete this!
const exampleLoggerMiddleware = define.middleware((ctx) => {
  console.log(`${ctx.req.method} ${ctx.req.url}`);
  return ctx.next();
});
app.use(exampleLoggerMiddleware);

// Include file-system based routes here
app.fsRoutes();

vite.config.ts

import { defineConfig } from "vite";
import { fresh } from "@fresh/plugin-vite";
import tailwindcss from "@tailwindcss/vite";

export default defineConfig({
  base: "/ui/",
  plugins: [fresh(), tailwindcss()],
});
  1. a.

Run in dev:

deno task dev
  1. a. See 404 errors for client-entry
Image
  1. b.

Run in prod:

deno task build
deno task start
  1. b. See 404 error for stylesheet, but client-entry is found. It is looking for it at http://localhost:8000/assets/client-entry-ByNlewOz.css?__frsh_c=
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions