router: Start: Invalid lazy handler result and v1.121.0 migration failing
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: https://github.com/TanStack/router/discussions/2863#discussioncomment-13104960. 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: https://github.com/TanStack/router/discussions/2863#discussioncomment-13104960
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
- Follow this migration guide: https://github.com/TanStack/router/discussions/2863#discussioncomment-13104960 with an older version of tanstack start
{ "@tanstack/react-router": "^1.120.5", "@tanstack/react-start": "^1.120.5", "vinxi": "^0.5.6", } - Run
npm run build - Run
npm run start - 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 https://github.com/TanStack/router/discussions/2863#discussioncomment-13104960 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
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 3
- Comments: 29 (10 by maintainers)
@Crsk thank you, let me take a look.
All, I removed the
topLevelAwait()plugin in myvite.config.tsfile, replaced all top level await code and I can build and start the server now.vite.config.ts@heystevegray thanks. Worked for me.
@JoelFickson This is how i did it:
vite.config.ts
wrangler.toml
package.json
Mmm there seems to be an issue with today’s released versions
1.121.17and1.121.18, i noticed node_module packages depending on these versions don’t have a dist folder causing not found errors here and there. My problems started to happen after deleted the lock file, new generated one depends on .17 or 18 even though i install packages with -E1.121.16@Crsk thanks for sharing.
@JoelFickson
app.config.tswas replaced byvite.config.tsas part of this migration guide https://github.com/TanStack/router/discussions/2863#discussioncomment-13104960If you mean Cloudflare Workers I’m not familiar with deploying that. I did find this section in the docs: https://tanstack.com/start/latest/docs/framework/react/hosting#cloudflare-pages
And you can change the
targetin the tanstack start plugin:@djgrant Thank you for the suggestion, but it did not work for me.
This morning I upgraded dependencies
I added
nitro.config.tsto my root directory. I rannpm run buildandnpm run startand I still seeAlso tried to pin the versions again this morning with
npx create-start-app@latest pin-versionsand this time it tried to install@tanstack/react-start-client@1.121.13which doesn’t exist.I see, it seems the helper from the bottom of this guide https://github.com/TanStack/router/discussions/2863#discussioncomment-13104960 (
npx create-start-app@latest pin-versions) is behaving in different ways.In my demo repository https://github.com/TanStack/router/issues/4431#issuecomment-2974669641 it added
@tanstack/react-router-devtools@1.121.13to the package.json which doesn’t exist.In my project repo I tried the same helper and it added
@tanstack/react-start-plugin@1.120.5to the package.json which doesn’t exist. https://www.npmjs.com/package/@tanstack/react-start-plugin?activeTab=versionsIf I manually install this version I can get my dev server running
But when I open localhost in the browser I see an issue with the loader data and the app never loads
please check if https://github.com/TanStack/router/issues/4432 is showing the same issue as you have with the “invalid lazy handler”
can you please share a failing reproducer?