Skip to content

Improve error message when file system route files have no exports #3652

@buttercat1791

Description

@buttercat1791

I encountered a bug while attempting to write a middleware while using filesystem-based routing that caused requests to API routes to fail.

My app defined a middleware to run on all routes in the file routes/_middleware.ts. When an island attempted to call an API endpoint under routes/api/, the request failed with the following error on the server:

Error: Expected a route, middleware, layout or error template, but couldn't find relevant exports in: undefined

I was able to create a minimal reproduction by simply adding a _middleware.ts file to the Fresh starter app (GitHub).

A workaround is possible by switching to programmatic routing rather than filesystem routing (example).

I am using Fresh v2.2.0 and Deno v2.5.6.

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