Skip to content

Start: "Invalid lazy handler result" when srcDirectory is root #4432

@djgrant

Description

@djgrant

Which project does this relate to?

Start

Describe the bug

When tsr.srcDirectory is set to . server routes and redirects trigger a nitro error "Invalid lazy handler result".

In browser:

{
  "error": true,
  "url": "http://[::]:3000/",
  "statusCode": 500,
  "statusMessage": "Server Error",
  "message": "Server Error"
}

In server logs:

[request error] [unhandled] [GET] https://5jd49m-3000.csb.app/
 TypeError: Invalid lazy handler result. It should be a function:
    at file:///project/workspace/.output/server/index.mjs:1473:17
    at async Object.handler (file:///project/workspace/.output/server/index.mjs:1557:19)
    at async Server.toNodeHandle (file:///project/workspace/.output/server/index.mjs:1828:7) {
  cause: TypeError: Invalid lazy handler result. It should be a function:
      at file:///project/workspace/.output/server/index.mjs:1473:17
      at async Object.handler (file:///project/workspace/.output/server/index.mjs:1557:19)
      at async Server.toNodeHandle (file:///project/workspace/.output/server/index.mjs:1828:7),
  statusCode: 500,
  fatal: false,
  unhandled: true,
  statusMessage: undefined,
  data: undefined
}

Note: this works ok in dev. It is only triggered by building and running a server (tested with node-server and aws-lambda targets).

Your Example Website or App

https://codesandbox.io/p/github/djgrant/repro-tanstack-start/invalid-lazy-handler

Steps to Reproduce the Bug or Issue

  1. Open sandbox
  2. Run npm run build
  3. Run node .output/server/index.mjs
  4. Open preview
  5. Observe output

Expected behavior

Server routes should not trigger this error.

Screenshots or Videos

No response

Platform

Any

Additional context

No response

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