Skip to content

filename.replace is not a function error when using @cloudflare/vite-plugin with SSR #9036

@BeiXiao

Description

@BeiXiao

Which Cloudflare product(s) does this pertain to?

Vite Plugin

What versions & operating system are you using?

^1.0.8

Please provide a link to a minimal reproduction

No response

Describe the Bug

filename.replace is not a function error when using @cloudflare/vite-plugin with SSR

Environment:

Using SSR build with cloudflare({ viteEnvironment: { name: "ssr" } }),

Error Description:
When configuring @cloudflare/vite-plugin with viteEnvironment: { name: "ssr" } in vite.config.ts, the build fails with the following error:

filename.replace is not a function
   at async ProxyServer.fetch (file:///.../node_modules/.pnpm/[email protected]/node_modules/miniflare/src/workers/core/proxy.worker.ts:173:11)
The error disappears when removing the viteEnvironment configuration.

Reproduction Steps:

Use the following configuration:

import { cloudflare } from "@cloudflare/vite-plugin";
import { reactRouter } from "@react-router/dev/vite";
import { defineConfig } from "vite";
import macrosPlugin from "vite-plugin-babel-macros";
import tsconfigPaths from "vite-tsconfig-paths";
import { lingui } from "@lingui/vite-plugin";

export default defineConfig(({ isSsrBuild }) => ({
  resolve: {
    alias: {
      "~": "/app",
    },
  },
  plugins: [
    macrosPlugin(),
    cloudflare({ viteEnvironment: { name: "ssr" } }), // Error occurs with this line
    reactRouter(),
    tsconfigPaths(),
    lingui({
      configPath: './lingui.config.ts',
    }),
  ],
  ssr: {
    noExternal: [
      "@udecode/plate-math",
      // ... other packages
    ]},
}));

Run the build with SSR enabled

Expected Behavior:
The build should complete successfully with SSR support enabled through viteEnvironment: { name: "ssr" }.

Actual Behavior:
Build fails with filename.replace is not a function error.

Additional Information:

The error appears to originate from miniflare's proxy worker

The issue is reproducible consistently with this configuration

Removing viteEnvironment configuration makes the error disappear, but we need SSR functionality

Workaround:
Currently, the only workaround is to remove the viteEnvironment configuration, which disables the needed SSR functionality.

Would appreciate any guidance on how to properly configure SSR with this setup. Thank you!

Metadata

Metadata

Assignees

Labels

bugSomething that isn't workingvite-pluginRelating to the `@cloudflare/vite-plugin` package

Type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions