router icon indicating copy to clipboard operation
router copied to clipboard

Start: Cloudflare worker deploy error after migration

Open erik-kroon opened this issue 7 months ago β€’ 1 comments

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

  1. vite build
  2. wrangler deploy

Expected behavior

successful deployment

Screenshots or Videos

Image

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(), ], });

erik-kroon avatar Jun 12 '25 10:06 erik-kroon

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...

mladenovic-13 avatar Jun 12 '25 12:06 mladenovic-13

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"]
}

atsuki44 avatar Jun 24 '25 15:06 atsuki44

Can this issue be closed?

brenelz avatar Jul 10 '25 21:07 brenelz