Skip to content

API routes have to be inline exported function declarations #1587

Closed

Description

@nnmrts

Describe the bug

This works

export async function GET(...parameters) {
  console.log(parameters);

  return new Response("test", { status: 200 });
};

while this doesn't

const GET = async (...parameters) => {
  console.log(parameters);

  return new Response("test", { status: 200 });
};

export { GET };

Your Example Website or App

n/a

Steps to Reproduce the Bug or Issue

  1. Create the second code example as an API route.
  2. Observe it responding with this
{
  "statusCode": 500,
  "stack": []
}

Expected behavior

It should just work like the first code example. Internally, this library probably uses function names instead of named export names to determine the endpoint functions. It shouldn't.

Screenshots or Videos

No response

Platform

  • OS: macOS Sequoia
  • Browser: Chrome
  • Version: 1.0.6

Additional context

No response

Activity

  1. transferred this issue fromsolidjs/solidon Jul 23, 2024
  2. brenelz commented on Jul 18, 2026

    @brenelz
    Contributor

    retested on the v2 beta; all export styles (named export of a const, export const, aliased specifiers) work for API routes in dev and production — fixed by the v2 route-analysis rewrite, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions