T
TanStack3mo ago
deep-jade

I started a new project with Clerk and Convex, target deployment to CF Workers, build errors

I set up development and production environments in wrangler.toml and I'm attempting deployments both via GH actions and locally, with zero success. The error I'm getting during the nitro build is this:
...
Error: [nitro] RollupError: Unexpected token `production`. Expected identifier in /home/runner/work/roundup-games/roundup-games/node_modules/.pnpm/vite@6.3.5_@types+node@24.0.4_jiti@2.4.2_lightningcss@1.30.1_terser@5.43.1_tsx@4.20.3/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js
15104: if (optimizerContext.cancelled) return { context: void 0, idToExports };
15105: const define = {
15106: ""production"": environment.config.keepProcessEnv ? (
^
15107: // define "production" even for keepProcessEnv === true
15108: // as esbuild will replace it automatically when `platform` is `'browser'`
error during build:
RollupError: Unexpected token `production`. Expected identifier in /home/runner/work/roundup-games/roundup-games/node_modules/.pnpm/vite@6.3.5_@types+node@24.0.4_jiti@2.4.2_lightningcss@1.30.1_terser@5.43.1_tsx@4.20.3/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js
...
...
Error: [nitro] RollupError: Unexpected token `production`. Expected identifier in /home/runner/work/roundup-games/roundup-games/node_modules/.pnpm/vite@6.3.5_@types+node@24.0.4_jiti@2.4.2_lightningcss@1.30.1_terser@5.43.1_tsx@4.20.3/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js
15104: if (optimizerContext.cancelled) return { context: void 0, idToExports };
15105: const define = {
15106: ""production"": environment.config.keepProcessEnv ? (
^
15107: // define "production" even for keepProcessEnv === true
15108: // as esbuild will replace it automatically when `platform` is `'browser'`
error during build:
RollupError: Unexpected token `production`. Expected identifier in /home/runner/work/roundup-games/roundup-games/node_modules/.pnpm/vite@6.3.5_@types+node@24.0.4_jiti@2.4.2_lightningcss@1.30.1_terser@5.43.1_tsx@4.20.3/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js
...
The vite build until nitro passes, .output/public gets generated.
6 Replies
deep-jade
deep-jadeOP3mo ago
"dependencies": { "@clerk/clerk-react": "^5.32.2", "@clerk/tanstack-react-start": "^0.17.0", "@clerk/tanstack-start": "^0.11.5", "@convex-dev/react-query": "0.0.0-alpha.8", "@dnd-kit/core": "^6.3.1", "@dnd-kit/modifiers": "^9.0.0", "@dnd-kit/sortable": "^10.0.0", "@dnd-kit/utilities": "^3.2.2", "@radix-ui/react-avatar": "^1.1.10", "@radix-ui/react-checkbox": "^1.3.2", "@radix-ui/react-dialog": "^1.1.14", "@radix-ui/react-dropdown-menu": "^2.1.15", "@radix-ui/react-label": "^2.1.7", "@radix-ui/react-select": "^2.2.5", "@radix-ui/react-separator": "^1.1.7", "@radix-ui/react-slot": "^1.2.3", "@radix-ui/react-tabs": "^1.1.12", "@radix-ui/react-toggle": "^1.1.9", "@radix-ui/react-toggle-group": "^1.1.10", "@radix-ui/react-tooltip": "^1.2.7", "@tabler/icons-react": "^3.34.0", "@tanstack/react-query": "^5.81.4", "@tanstack/react-query-devtools": "^5.81.4", "@tanstack/react-router": "^1.121.41", "@tanstack/react-router-with-query": "^1.121.41", "@tanstack/react-start": "^1.121.41", "@tanstack/react-start-config": "^1.120.20", "@tanstack/react-table": "^8.21.3", "@tanstack/router-devtools": "^1.121.41", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "convex": "^1.25.0", "convex-helpers": "^0.1.95", "lucide-react": "^0.487.0", "next-themes": "^0.4.6", "nitropack": "^2.11.13", "react": "^19.1.0", "react-dom": "^19.1.0", "sonner": "^2.0.5", "tailwind-merge": "^3.3.1", "tailwindcss": "^4.1.11", "tw-animate-css": "^1.3.4", "unenv": "^1.10.0", "vaul": "^1.1.2", "vinxi": "^0.5.7", "zod": "^3.25.67" }, "devDependencies": { "@cloudflare/vite-plugin": "^1.7.5", "@cloudflare/workers-types": "^4.20250627.0", "@eslint/js": "^9.29.0", "@tailwindcss/vite": "^4.1.11", "@tanstack/react-router-devtools": "^1.121.41", "@tanstack/router-plugin": "^1.121.41", "@types/node": "24.0.4", "@types/react": "^19.1.8", "@types/react-dom": "^19.1.6", "@vitejs/plugin-react": "^4.6.0", "esbuild": "^0.25.5", "eslint": "^9.29.0", "eslint-plugin-react-hooks": "^5.2.0", "eslint-plugin-react-refresh": "^0.4.20", "globals": "^15.15.0", "typescript": "5.8.3", "typescript-eslint": "^8.35.0", "vite": "^6.3.5", "vite-tsconfig-paths": "^5.1.4", "wrangler": "^4.22.0" } app.config.ts:
import { defineConfig } from '@tanstack/react-start-config'
import tsConfigPaths from 'vite-tsconfig-paths'
import { cloudflare } from 'unenv'

export default defineConfig({
tsr: {
appDirectory: 'src',
},
server: {
preset: 'cloudflare-module',
unenv: cloudflare,
esbuild: {
options: {},
},
},
vite: {
plugins: [
tsConfigPaths({
projects: ['./tsconfig.json'],
}),
],
},
})
import { defineConfig } from '@tanstack/react-start-config'
import tsConfigPaths from 'vite-tsconfig-paths'
import { cloudflare } from 'unenv'

export default defineConfig({
tsr: {
appDirectory: 'src',
},
server: {
preset: 'cloudflare-module',
unenv: cloudflare,
esbuild: {
options: {},
},
},
vite: {
plugins: [
tsConfigPaths({
projects: ['./tsconfig.json'],
}),
],
},
})
vite.config.ts:
import { tanstackStart } from '@tanstack/react-start/plugin/vite'
import { defineConfig } from "vite";
import { TanStackRouterVite } from "@tanstack/router-plugin/vite";

import path from "path";
import tailwindcss from "@tailwindcss/vite";
import tsConfigPaths from 'vite-tsconfig-paths'

export default defineConfig({
plugins: [
TanStackRouterVite({
target: "react",
autoCodeSplitting: true,
routesDirectory: "./src/routes",
}),

tailwindcss(),
tsConfigPaths({
projects: ['./tsconfig.json'],
}),
tanstackStart({
target: "cloudflare-module",
}),
],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
"@worker": path.resolve(__dirname, "./worker"),
"convex/_generated/api": path.resolve(__dirname, "./convex/_generated/api.js"),
"react": path.resolve(__dirname, "node_modules/react"),
"react-dom": path.resolve(__dirname, "node_modules/react-dom"),
},
},
ssr: {
noExternal: ["convex", "convex/_generated/api"],
},

build: {
target: "esnext", // Cloudflare Workers require modern ES features
sourcemap: false, // Generate source maps for production
chunkSizeWarningLimit: 1000, // Increase chunk size warning limit to 1MB
rollupOptions: {
treeshake: true,
output: {
sourcemapIgnoreList: (relativeSourcePath) => {
// Exclude installHook.js from source maps
return relativeSourcePath.includes('installHook.js');
},
},
},
minify: true,
},
optimizeDeps: {
esbuildOptions: {
// Node.js global to browser globalThis
define: {
global: 'globalThis'
}
}
}
});
import { tanstackStart } from '@tanstack/react-start/plugin/vite'
import { defineConfig } from "vite";
import { TanStackRouterVite } from "@tanstack/router-plugin/vite";

import path from "path";
import tailwindcss from "@tailwindcss/vite";
import tsConfigPaths from 'vite-tsconfig-paths'

export default defineConfig({
plugins: [
TanStackRouterVite({
target: "react",
autoCodeSplitting: true,
routesDirectory: "./src/routes",
}),

tailwindcss(),
tsConfigPaths({
projects: ['./tsconfig.json'],
}),
tanstackStart({
target: "cloudflare-module",
}),
],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
"@worker": path.resolve(__dirname, "./worker"),
"convex/_generated/api": path.resolve(__dirname, "./convex/_generated/api.js"),
"react": path.resolve(__dirname, "node_modules/react"),
"react-dom": path.resolve(__dirname, "node_modules/react-dom"),
},
},
ssr: {
noExternal: ["convex", "convex/_generated/api"],
},

build: {
target: "esnext", // Cloudflare Workers require modern ES features
sourcemap: false, // Generate source maps for production
chunkSizeWarningLimit: 1000, // Increase chunk size warning limit to 1MB
rollupOptions: {
treeshake: true,
output: {
sourcemapIgnoreList: (relativeSourcePath) => {
// Exclude installHook.js from source maps
return relativeSourcePath.includes('installHook.js');
},
},
},
minify: true,
},
optimizeDeps: {
esbuildOptions: {
// Node.js global to browser globalThis
define: {
global: 'globalThis'
}
}
}
});
wrangler.toml:
name = "roundup-games"
main = ".output/server/index.mjs"
compatibility_date = "2025-06-26"
compatibility_flags = ["nodejs_compat"]

[assets]
directory = ".output/public/"
binding = "ASSETS"
not_found_handling = "single-page-application"

[observability]
enabled = true

[env.development]
name = "roundup-games-dev"
workers_dev = true
routes = [
{ pattern = "dev.roundup.games/*", zone_name = "roundup.games" }
]

[env.development.vars]
VITE_CONVEX_URL = "..."
VITE_CLERK_PUBLISHABLE_KEY = "..."

[env.production]
name = "roundup-games"

routes = [
{ pattern = "www.roundup.games/*", zone_name = "roundup.games" }
]

[env.production.vars]
VITE_CONVEX_URL = "..."
VITE_CLERK_PUBLISHABLE_KEY = "..."
name = "roundup-games"
main = ".output/server/index.mjs"
compatibility_date = "2025-06-26"
compatibility_flags = ["nodejs_compat"]

[assets]
directory = ".output/public/"
binding = "ASSETS"
not_found_handling = "single-page-application"

[observability]
enabled = true

[env.development]
name = "roundup-games-dev"
workers_dev = true
routes = [
{ pattern = "dev.roundup.games/*", zone_name = "roundup.games" }
]

[env.development.vars]
VITE_CONVEX_URL = "..."
VITE_CLERK_PUBLISHABLE_KEY = "..."

[env.production]
name = "roundup-games"

routes = [
{ pattern = "www.roundup.games/*", zone_name = "roundup.games" }
]

[env.production.vars]
VITE_CONVEX_URL = "..."
VITE_CLERK_PUBLISHABLE_KEY = "..."
I've been banging my head against this the whole day, with extremely limited success, anyone have an idea what might be wrong? Ah, forgot to mention, build command is tsc -b && CLOUDFLARE_ENV=development vite build --mode development
sensitive-blue
sensitive-blue3mo ago
which depdency is this?
15104: if (optimizerContext.cancelled) return { context: void 0, idToExports };
15105: const define = {
15106: ""production"": environment.config.keepProcessEnv ? (
^
15107: // define "production" even for keepProcessEnv === true
15108: // as esbuild will replace it automatically when `platform` is `'browser'`
15104: if (optimizerContext.cancelled) return { context: void 0, idToExports };
15105: const define = {
15106: ""production"": environment.config.keepProcessEnv ? (
^
15107: // define "production" even for keepProcessEnv === true
15108: // as esbuild will replace it automatically when `platform` is `'browser'`
deep-jade
deep-jadeOP3mo ago
GitHub
vite/packages/vite/src/node/optimizer/index.ts at ac528a44c384fefb6...
Next generation frontend tooling. It's fast! Contribute to vitejs/vite development by creating an account on GitHub.
deep-jade
deep-jadeOP3mo ago
but from what I understand, during rollup the ""production""bit should be replaced dynamically by the actual `mode passed to vite - I guess? and something happens somewhere in the chain causing this to fail this is the actual stack:
error during build:
RollupError: Unexpected token `production`. Expected identifier in /Users/elis/Work/roundup-games/node_modules/.pnpm/vite@6.3.5_@types+node@24.0.4_jiti@2.4.2_lightningcss@1.30.1_terser@5.43.1_tsx@4.20.3/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js
at getRollupError (file:///Users/elis/Work/roundup-games/node_modules/.pnpm/rollup@4.44.1/node_modules/rollup/dist/es/shared/parseAst.js:401:41)
at convertProgram (file:///Users/elis/Work/roundup-games/node_modules/.pnpm/rollup@4.44.1/node_modules/rollup/dist/es/shared/parseAst.js:1089:26)
at parseAst (file:///Users/elis/Work/roundup-games/node_modules/.pnpm/rollup@4.44.1/node_modules/rollup/dist/es/shared/parseAst.js:2074:87)
at tryParse (file:///Users/elis/Work/roundup-games/node_modules/.pnpm/@rollup+plugin-commonjs@28.0.6_rollup@4.44.1/node_modules/@rollup/plugin-commonjs/dist/es/index.js:17:12)
at analyzeTopLevelStatements (file:///Users/elis/Work/roundup-games/node_modules/.pnpm/@rollup+plugin-commonjs@28.0.6_rollup@4.44.1/node_modules/@rollup/plugin-commonjs/dist/es/index.js:37:15)
at Object.transformAndCheckExports (file:///Users/elis/Work/roundup-games/node_modules/.pnpm/@rollup+plugin-commonjs@28.0.6_rollup@4.44.1/node_modules/@rollup/plugin-commonjs/dist/es/index.js:2117:68)
at Object.transform (file:///Users/elis/Work/roundup-games/node_modules/.pnpm/@rollup+plugin-commonjs@28.0.6_rollup@4.44.1/node_modules/@rollup/plugin-commonjs/dist/es/index.js:2321:41)
at file:///Users/elis/Work/roundup-games/node_modules/.pnpm/rollup@4.44.1/node_modules/rollup/dist/es/shared/node-entry.js:22288:40
 ELIFECYCLE  Command failed with exit code 1.
error during build:
RollupError: Unexpected token `production`. Expected identifier in /Users/elis/Work/roundup-games/node_modules/.pnpm/vite@6.3.5_@types+node@24.0.4_jiti@2.4.2_lightningcss@1.30.1_terser@5.43.1_tsx@4.20.3/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js
at getRollupError (file:///Users/elis/Work/roundup-games/node_modules/.pnpm/rollup@4.44.1/node_modules/rollup/dist/es/shared/parseAst.js:401:41)
at convertProgram (file:///Users/elis/Work/roundup-games/node_modules/.pnpm/rollup@4.44.1/node_modules/rollup/dist/es/shared/parseAst.js:1089:26)
at parseAst (file:///Users/elis/Work/roundup-games/node_modules/.pnpm/rollup@4.44.1/node_modules/rollup/dist/es/shared/parseAst.js:2074:87)
at tryParse (file:///Users/elis/Work/roundup-games/node_modules/.pnpm/@rollup+plugin-commonjs@28.0.6_rollup@4.44.1/node_modules/@rollup/plugin-commonjs/dist/es/index.js:17:12)
at analyzeTopLevelStatements (file:///Users/elis/Work/roundup-games/node_modules/.pnpm/@rollup+plugin-commonjs@28.0.6_rollup@4.44.1/node_modules/@rollup/plugin-commonjs/dist/es/index.js:37:15)
at Object.transformAndCheckExports (file:///Users/elis/Work/roundup-games/node_modules/.pnpm/@rollup+plugin-commonjs@28.0.6_rollup@4.44.1/node_modules/@rollup/plugin-commonjs/dist/es/index.js:2117:68)
at Object.transform (file:///Users/elis/Work/roundup-games/node_modules/.pnpm/@rollup+plugin-commonjs@28.0.6_rollup@4.44.1/node_modules/@rollup/plugin-commonjs/dist/es/index.js:2321:41)
at file:///Users/elis/Work/roundup-games/node_modules/.pnpm/rollup@4.44.1/node_modules/rollup/dist/es/shared/node-entry.js:22288:40
 ELIFECYCLE  Command failed with exit code 1.
sensitive-blue
sensitive-blue3mo ago
so you are still on the old vinxi version, right? but no, this does not make sense why do you have an app.config.ts ?
deep-jade
deep-jadeOP3mo ago
F me, I didn't even consider it, it was just there from the project I used as baseline - I deleted it and the build now passes, thank you! ❤️

Did you find this page helpful?