Skip to content

Start: Invalid lazy handler result and v1.121.0 migration failing #4431

Open
@heystevegray

Description

@heystevegray

Which project does this relate to?

Start

Describe the bug

The bug

A few days ago I couldn't start my dev server anymore with npm run dev.

npm run dev

> app@1.0.0 dev
> vinxi dev --host

vinxi v0.5.7
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './config' is not defined by "exports" in /Users/me/app/node_modules/@tanstack/react-start/package.json imported from /Users/me/app/app.config.timestamp_1750004498370.js
    at exportsNotFound (node:internal/modules/esm/resolve:296:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:643:9)
    at packageResolve (node:internal/modules/esm/resolve:823:14)
    at moduleResolve (node:internal/modules/esm/resolve:907:18)
    at defaultResolve (node:internal/modules/esm/resolve:1037:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:650:12)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:599:25)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:582:38)
    at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:241:38)
    at ModuleJob._link (node:internal/modules/esm/module_job:132:49) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

 ERROR  Cannot read properties of undefined (reading 'config')                                                                             12:21:38 PM

    at Object.run (node_modules/vinxi/bin/cli.mjs:79:9)
    at async runCommand (node_modules/citty/dist/index.mjs:316:16)
    at async runCommand (node_modules/citty/dist/index.mjs:307:11)
    at async runMain (node_modules/citty/dist/index.mjs:445:7) 



 ERROR  Cannot read properties of undefined (reading 'config')                                                                             12:21:38 PM

My package.json looked like this:

{
  "@tanstack/react-router": "^1.120.5",
  "@tanstack/react-start": "^1.120.5",
  "vinxi": "^0.5.6",
}

Trying to migrate

I then found this migration guide for v1.121.0 in Start BETA - Tracking: #2863 (comment). In a new branch I followed these steps. Then I ran npm run build and npm run start and I see this error:

TypeError: Invalid lazy handler result. It should be a function: at file:///Users/me/app/.output/server/index.mjs:1473:17

My localhost shows this in the browser:

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

And my terminal shows this:

 npm run start

> app@1.0.0 start
> node .output/server/index.mjs

Listening on http://[::]:3000
[request error] [unhandled] [GET] http://[::]:3000/
 TypeError: Invalid lazy handler result. It should be a function:
    at file:///Users/me/app/.output/server/index.mjs:1473:17
    at async Object.handler (file:///Users/me/app/.output/server/index.mjs:1557:19)
    at async Server.toNodeHandle (file:///Users/me/app/.output/server/index.mjs:1828:7) {
  cause: TypeError: Invalid lazy handler result. It should be a function:
      at file:///Users/me/app/.output/server/index.mjs:1473:17
      at async Object.handler (file:///Users/me/app/.output/server/index.mjs:1557:19)
      at async Server.toNodeHandle (file:///Users/me/app/.output/server/index.mjs:1828:7),
  statusCode: 500,
  fatal: false,
  unhandled: true,
  statusMessage: undefined,
  data: undefined
}
[unhandledRejection] Error: Invalid environment variables
    at onValidationError (file:///Users/me/app/.output/server/node_modules/@t3-oss/env-core/dist/src-Cq4nGjdj.js:53:9)
    at createEnv (file:///Users/me/app/.output/server/node_modules/@t3-oss/env-core/dist/src-Cq4nGjdj.js:58:28)
    at file:///Users/me/app/.output/server/chunks/_/ssr.mjs:2136:15
    at file:///Users/me/app/.output/server/chunks/_/ssr.mjs:5818:3
    at ModuleJob.run (node:internal/modules/esm/module_job:268:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:543:26)
    at async Object.handler (file:///Users/me/app/.output/server/index.mjs:1557:19)
    at async Server.toNodeHandle (file:///Users/me/app/.output/server/index.mjs:1828:7)
[request error] [unhandled] [GET] http://[::]:3000/favicon.ico
 TypeError: Invalid lazy handler result. It should be a function:
    at file:///Users/me/app/.output/server/index.mjs:1473:17
    at async Object.handler (file:///Users/me/app/.output/server/index.mjs:1557:19)
    at async Server.toNodeHandle (file:///Users/me/app/.output/server/index.mjs:1828:7) {
  cause: TypeError: Invalid lazy handler result. It should be a function:
      at file:///Users/me/app/.output/server/index.mjs:1473:17
      at async Object.handler (file:///Users/me/app/.output/server/index.mjs:1557:19)
      at async Server.toNodeHandle (file:///Users/me/app/.output/server/index.mjs:1828:7),
  statusCode: 500,
  fatal: false,
  unhandled: true,
  statusMessage: undefined,
  data: undefined
}

Here is my vite.config.ts file. I'm trying to use https://env.t3.gg/docs/core for environment variable safety, thats why you see these lines:

import 'dotenv/config'
import './src/env'

My vite.config.ts file:

import { tanstackStart } from '@tanstack/react-start/plugin/vite'
import { defineConfig } from 'vite'
import topLevelAwait from 'vite-plugin-top-level-await'
import tsConfigPaths from 'vite-tsconfig-paths'
import 'dotenv/config'
import './src/env'

export default defineConfig({
  server: {
    port: 3000,
  },
  plugins: [
    tsConfigPaths({
      projects: ['./tsconfig.json'],
    }),
    tanstackStart({
      target: 'node-server',
    }),
    topLevelAwait(),
  ],
})

Not migrating at this time

I also attempted the "pinning" suggestion at the bottom of this link: #2863 (comment)

npx create-start-app@latest pin-versions
10 packages updated.

Remove your node_modules directory and package lock file and re-install.

This updated the following packages in my package.json file

{
  "@tanstack/react-router": "1.120.5",
  "@tanstack/react-router-devtools": "1.120.5",
  "@tanstack/react-start": "1.120.5",
  "@tanstack/react-start-client": "1.120.5",
  "@tanstack/react-start-config": "1.120.5",
  "@tanstack/react-start-plugin": "1.120.5",
  "@tanstack/react-start-server": "1.120.5",
  "@tanstack/router-generator": "1.120.5",
  "@tanstack/router-plugin": "1.120.5",
  "@tanstack/start-server-core": "1.120.5",
}

I removed node_modules and package-lock.json, then ran npm i again. But then I see this error:

No matching version found for @tanstack/react-start-plugin@1.120.5

npm i

npm error code ETARGET
npm error notarget No matching version found for @tanstack/react-start-plugin@1.120.5.
npm error notarget In most cases you or one of your dependencies are requesting
npm error notarget a package version that doesn't exist.
npm error A complete log of this run can be found in: /Users/me/.npm/_logs/2025-06-15T17_20_33_118Z-debug-0.log

New project

I followed the steps here to build a project from scratch and I can successfully run npm run build and npm run start with these scripts:

"scripts": {
  "dev": "vite dev",
  "build": "vite build",
  "start": "node .output/server/index.mjs"
}

My working example repo is here: https://github.com/heystevegray/tanstack-start-beta-bug

I'm not sure why a new project seems to work but mine cannot start.

Your Example Website or App

https://github.com/heystevegray/tanstack-start-beta-bug

Steps to Reproduce the Bug or Issue

  1. Follow this migration guide: Start BETA - Tracking #2863 (comment) with an older version of tanstack start
    {
      "@tanstack/react-router": "^1.120.5",
      "@tanstack/react-start": "^1.120.5",
      "vinxi": "^0.5.6",
    }
  2. Run npm run build
  3. Run npm run start
  4. I see this in the terminal:

    TypeError: Invalid lazy handler result. It should be a function:
    at file:///Users/me/app/.output/server/index.mjs:1473:17

Expected behavior

I expect after following the migration guide here #2863 (comment) that I can build and start my project with:

"start": "node .output/server/index.mjs"

Screenshots or Videos

No response

Platform

  • OS: macOS
  • Browser: Arc
  • Version: Arc 1.99.0 (64212)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    information neededFurther information is requestedstartEverything about TanStack Start

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions