Start: Cloudflare worker deploy error after migration
Which project does this relate to?
Start
Describe the bug
after migrating, wrangler deploy errors out. worked before migration
β Nitro Server built nitro 11:09:52 AM
ββ .output/server/index.mjs (2.6 MB) (667 kB gzip)
Ξ£ Total size: 2.6 MB (667 kB gzip)
[nitro 11:09:52 AM] β You can preview this build using npx wrangler dev .output/server/index.mjs --site .output/public
β You can deploy this build using npx wrangler deploy nitro 11:09:52 AM
[nitro 11:09:52 AM] β Client and Server bundles for TanStack Start have been successfully built.
bunx wrangler deploy
β
οΈ wrangler 4.19.2
βββββββββββββββββββ
β² [WARNING] Using direct eval with a bundler is not recommended and may cause problems [direct-eval]
.output/server/index.mjs:1:1654555:
1 β ...ped_bm_rt,expression_function=eval("[function _expression_functi...
β΅ ~~~~
You can read more about direct eval and bundling here: https://esbuild.github.io/link/direct-eval
β [ERROR] Build failed with 1 error:
β [ERROR] Unexpected external import of
"node:events", "node:perf_hooks", "node:stream", and "node:tty".
Your worker has no default export, which means it is assumed to be a Service
Worker format Worker.
Did you mean to create a ES Module format Worker?
If so, try adding `export default { ... }` in your entry-point.
See
https://developers.cloudflare.com/workers/reference/migrate-to-module-workers/.
[plugin hybrid-nodejs_compat]
β² [WARNING] Using direct eval with a bundler is not recommended and may cause problems [direct-eval]
.output/server/index.mjs:1:1654555:
1 β ...ped_bm_rt,expression_function=eval("[function _expression_functi...
β΅ ~~~~
You can read more about direct eval and bundling here: https://esbuild.github.io/link/direct-eval
πͺ΅ Logs were written to "/Users/erik/Library/Preferences/.wrangler/logs/wrangler-2025-06-12_09-10-52_855.log"
Your Example Website or App
sorry don't have
Steps to Reproduce the Bug or Issue
- vite build
- wrangler deploy
Expected behavior
successful deployment
Screenshots or Videos
Platform
"@tanstack/react-form": "^1.11.1", "@tanstack/react-query": "^5.71.10", "@tanstack/react-router": "^1.121.0-alpha.27", "@tanstack/react-router-with-query": "^1.121.0", "@tanstack/react-start": "^1.121.0-alpha.27", "@tanstack/react-start-config": "^1.120.20", "@tanstack/react-table": "8.21.2", "@tanstack/router-plugin": "^1.121.0",
OS: macOS 14.6.1 Memory: 16 GiB Architecture: aarch64
Additional context
import viteTsConfigPaths from "vite-tsconfig-paths"; import tailwindcss from "@tailwindcss/vite"; import { tanstackStart } from "@tanstack/react-start/plugin/vite"; import { defineConfig } from "vite";
export default defineConfig({ plugins: [ tanstackStart({ target: "cloudflare", }), viteTsConfigPaths({ projects: ["./tsconfig.json"], }), tailwindcss(), ], });
I think the correct target should be target: 'cloudflare-module', but that doesnβt necessarily mean it will solve the issueβ¦ I had a somewhat similar problem with CF Pages...
I resolved this for Cloudflare Workers deployment with this configuration:
// vite.config.ts
import { cloudflare } from "unenv";
import nitroCloudflareBindings from "nitro-cloudflare-dev";
const untypedOptions = {
unenv: cloudflare,
modules: [nitroCloudflareBindings],
} as any; // Current type definitions are incomplete, casting needed
export default defineConfig({
plugins: [
tanstackStart({
target: "cloudflare-module",
...untypedOptions,
}),
],
});
{
"dependencies": {
"@tanstack/react-query": "^5.66.0",
"@tanstack/react-query-devtools": "^5.66.0",
"@tanstack/react-router": "^1.121.34",
"@tanstack/react-router-devtools": "^1.121.34",
"@tanstack/react-router-with-query": "^1.121.34",
"@tanstack/react-start": "^1.121.35",
"nitro-cloudflare-dev": "^0.2.2",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"redaxios": "^0.5.1",
"tailwind-merge": "^2.6.0",
"unenv": "^1.10.0"
},
"devDependencies": {
"@tailwindcss/vite": "^4.1.10",
"@types/node": "^22.5.4",
"@types/react": "^19.0.8",
"@types/react-dom": "^19.0.3",
"tailwindcss": "^4.1.10",
"typescript": "^5.7.2",
"vite": "^6.3.5",
"vite-tsconfig-paths": "^5.1.4",
"wrangler": "^4.20.2"
}
}
{
"$schema": "node_modules/wrangler/config-schema.json",
"name": "tanstack-start-cf-workers",
"compatibility_date": "2025-06-18",
"main": "./.output/server/index.mjs",
"observability": {
"enabled": true
},
"assets": {
"directory": "./.output/public/"
},
"compatibility_flags": ["nodejs_compat"]
}
Can this issue be closed?