Skip to content

devinxi: Environment error attempting to use @cloudflare/vite-plugin #4161

Closed

Description

@jasongitmail

Which project does this relate to?

Router

Describe the bug

If you add the cloudflare vite plugin, the vite dev server will fail to start with an error. (Without this plugin, I have the dev server working.)

import { cloudflare } from "@cloudflare/vite-plugin";
import { tanstackStart } from '@tanstack/react-start/plugin/vite';
import { defineConfig } from 'vite';

export default defineConfig({
  plugins: [
    cloudflare(),
    tanstackStart({
      tsr: {
        target: 'react',
        autoCodeSplitting: true,
        verboseFileRoutes: false,
        virtualRouteConfig: './routes.ts',
      },
      target: "cloudflare_module",
    }),
  ],
});

Your Example Website or App

https://github.com/jasongitmail/tanstack-vite-cloudflare-repro

Steps to Reproduce the Bug or Issue

git clone https://github.com/jasongitmail/tanstack-vite-cloudflare-repro.git
git checkout 2d0009a  # in case I've moved it forward
bun install
bun run build

Expected behavior

Vite dev server should start without error.

Screenshots or Videos

$ vite --port 3000


WARNING: your worker config (at `wrangler.jsonc`) contains the following configuration options which are ignored since they are not applicable when using Vite:
  - `build` which is not relevant in the context of a Vite project

error when starting dev server:
Error: The following environment configurations are incompatible with the Cloudflare Vite plugin:
        - "tanstack_vite_cloudflare_repro" environment: `resolve.external`: ["undici"]
To resolve this issue, avoid setting `optimizeDeps.exclude` and `resolve.external` in your Cloudflare Worker environments.

    at validateWorkerEnvironmentsResolvedConfigs (file:///Users/me/tanstack-vite-cloudflare-repro/node_modules/@cloudflare/vite-plugin/dist/index.js:14267:11)
    at configResolved (file:///Users/me/tanstack-vite-cloudflare-repro/node_modules/@cloudflare/vite-plugin/dist/index.js:14363:11)
    at file:///Users/me/tanstack-vite-cloudflare-repro/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:49086:67
    at Array.map (<anonymous>)
    at resolveConfig (file:///Users/me/tanstack-vite-cloudflare-repro/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:49086:53)
    at async _createServer (file:///Users/me/tanstack-vite-cloudflare-repro/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:38329:18)
    at async CAC.<anonymous> (file:///Users/me/tanstack-vite-cloudflare-repro/node_modules/vite/dist/node/cli.js:753:20)
error: script "dev" exited with code 1

Platform

  • OS: macOS
  • Browser: n/a
  • Version:
    "@tailwindcss/vite": "^4.1.6",
    "@tanstack/react-router": "^1.120.4-alpha.12",
    "@tanstack/react-router-devtools": "^1.120.4-alpha.1",
    "@tanstack/react-start": "^1.120.4-alpha.12",
    "@tanstack/virtual-file-routes": "^1.120.4-alpha.1",
    "@cloudflare/vite-plugin": "^1.1.1",
    "vite": "^6.1.0",
    "wrangler": "^4.14.4"

Additional context

  • ordering the cloudflare plugin before or after tanstack plugin makes no difference. both result in this same error.
  • Looks like undici is a dependency of @tanstack/start-server-core, it may be there.

Activity

  1. jasongitmail commented on May 14, 2025

    @jasongitmail
    Author

    @schiller-manuel fixed this in a newer alpha release.

    As a side note: we also discovered that this plugin doesn't do anything useful right now, since getPlatformProxy() from wrangler is needed to get the env currently. But Manuel said first class support for Tanstack by @cloudflare/vite-plugin will be coming.

    Closing b/c this issue related to a specific error that is now resolved.

  2. andreilgeorgescu commented on May 21, 2025

    @andreilgeorgescu

    So what is currently the recommended way to work with Cloudflare in Tanstack Start/Router?

    I followed Cloudflare's Tanstack guide but from what I can tell it requires me to pnpm run build prior to npx wrangler dev which takes a long time. I'm assuming we have to just wait until the Vite plugin supports Tanstack?

  3. HoaX7 commented on Oct 2, 2025

    @HoaX7

    any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions